考虑以下 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 Text 1”的第一个单词(即“Text”)之间的间距为正常间距。由于“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}