
考慮以下 MWE:
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line \mbox{\parbox[t][][t]{\textwidth-\widthof{MMMx This is a line}}{
\begin{enumerate}[label=\textit{(\roman{enumii})}]
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2
\end{enumerate}
}}\end{enumerate}
我有疑問:
1) 我希望「(i) Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1」與「This is a line」顯示在同一行。我怎樣才能做到這一點 ?
2)我想要「This is a line」的最後一個單字(即「line」)和「(i) Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1」的第一個單字之間的間距,即「文本」是正常的空間。因為「This is a line」已經縮進,所以我嘗試透過新增「MMMx」作為 中的附加間距來解釋這種縮排\widthof
。但這只是目測。我怎樣才能做到這一點?
答案1
無需猜測;使用minipage
代替\parbox
並刪除\mbox
:
\documentclass{article}
\usepackage{enumitem,calc}
\begin{document}
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line
\begin{minipage}[t]{\textwidth-\labelwidth-\labelsep-\widthof{This is a line}}
\begin{enumerate}[label=(\textit{\roman*})]
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{enumerate}
\end{minipage}
\end{enumerate}
\end{document}
更好的定義,允許在每個層級進行嵌套;但請記住,嵌套多個枚舉是不好的風格。
\documentclass{article}
\usepackage{showframe} % just for showing the page margins
\usepackage{enumitem,calc}
\newenvironment{xenumerate}[1]
{\begin{minipage}[t]{\linewidth-\widthof{#1}}
\begin{enumerate}[label=(\textit{\roman*})]}
{\end{enumerate}\end{minipage}}
\begin{document}
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line
\begin{xenumerate}{This is a line}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item Text text text text text text
\begin{enumerate}
\item Text Text Text Text
\begin{xenumerate}{Text Text Text Text}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item End of the story
\end{enumerate}
\end{enumerate}
\end{document}
帶有用於更改標籤的可選參數的版本
預設標籤label=(\textit{\roman*})
與以前一樣,但您可以根據需要更改它。
\documentclass{article}
\usepackage{showframe}
\usepackage{enumitem,calc}
\newenvironment{xenumerate}[2][label=(\textit{\roman*})]
{\begin{minipage}[t]{\linewidth-\widthof{#2}}
\begin{enumerate}[#1]}
{\end{enumerate}\end{minipage}}
\begin{document}
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line
\begin{xenumerate}{This is a line}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item Text text text text text text
\begin{enumerate}
\item Text Text Text Text
\begin{xenumerate}[label=(\arabic*)]{Text Text Text Text}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item End of the story
\end{enumerate}
\end{enumerate}
\end{document}