我有一个描述列表,其中的标签一行放不下。我想在标签中设置换行符,这样标签的第二行就不会缩进。但我仍然希望正文缩进。(为了让正文从新行开始,我使用了一个 hack ~\\
— 也许有更好的解决方案?)
\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}
\begin{document}
\begin{description}[style=unboxed]
\item[
This is a too long label.
It would not be if I did not add this sentence.
I do not want this line to be indented.
]~\\
However, I want the body of the item to be, just as it is.
\lipsum[1]
\item[An item with a short label.]~\\
This looks good.
\lipsum[1]
\end{description}
\end{document}
答案1
这是不对的——它会产生过满的盒子。然而,也许其他人会发现这是更好解决方案的有用基础。
\documentclass{article}
\usepackage{enumitem,calc}
\usepackage{lipsum}
\makeatletter
\SetLabelAlign{myparleft}{\parbox[t]\textwidth{#1\par\mbox{}}}
\makeatother
\begin{document}
\lipsum[1]
\begin{description}[align=myparleft]
\item[%
This is a too long label.
It would not be if I did not add this sentence.
I do not want this line to be indented.
]
However, I want the body of the item to be, just as it is.
\lipsum[1]
\item[An item with a short label.]
This looks good.
\lipsum[1]
\end{description}
\end{document}
答案2
基于 cfr 的回答,这里有两个解决方案。但是它需要手动设置描述中的行数。
\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}
\begin{document}
\begin{description}[style=unboxed]
\item[\protect{%
\parbox[t][2\baselineskip][t]{\textwidth}{%
This is a too long label.
It would not be if I did not add this sentence.
I do not want this line to be indented.
}
}]
Now this looks good,
with the description wrapped in a parbox.
\lipsum[75]
\item[An item with a short label.]~\\
This looks good.
\lipsum[66]
\item[\protect{%
\begin{minipage}[t][2\baselineskip][t]{\textwidth}
This is a too long label.
It would not be if I did not add this sentence.
I do not want this line to be indented.
\end{minipage}
}]
And this looks good too,
with the description wrapped in a minipage.
\lipsum[75]
\end{description}
\end{document}