我是 TeX/LaTeX 的新手,我希望能够根据需要将 (描述) 列表的项目标签排版为多行。我购买了一份《The LaTeX Companion》,第 3 章包含的示例代码几乎完全符合我的要求(略微修改了 tlc2 中的清单 3-3-29):
\documentclass{article}
\pagestyle{empty} % produces empty heads and feet -- no page numbers
\usepackage{calc}
\newenvironment{Description}
{\begin{list}{}{\let\makelabel\Descriptionlabel
\setlength\labelwidth{40pt}%
\setlength\leftmargin{\labelwidth+\labelsep}}}%
{\end{list}}
\newcommand*\Descriptionlabel[1]
{\raisebox{0pt}[1ex][0pt]%
{\makebox[\labelwidth][l]%
{\parbox[t]{\labelwidth}%
{\hspace{0pt}#1:}}}}
\begin{document}
\begin{Description}
\item[Description] Returns from a function. If issued at top level, the
interpreter simply terminates, just as if end of input had been
reached.
\item[Errors] None.
\item[Return\\values]
Any arguments in effect are passed back to the caller.
\end{Description}
\end{document}
如果标签对应的“说明”行数大于或等于标签生成的行数,则此方法有效。但如果标签的行数多于说明的行数,则后面的项目在垂直方向上设置得离前面的项目有点太近,如下所示,使用相同的代码:
在项目标签包含的行数多于其描述的特殊情况下,如何获得正确的项目间距?
答案1
正如@Steven B. Segletes 所说,您必须手动添加空行。我想提请您注意,使用该enumitem
包要简单得多,它已经有了multiline
描述标签的样式。它可以像这样:
\documentclass{article}
\pagestyle{empty} % produces empty heads and feet -- no page numbers
\usepackage{enumitem}
\setlist[description]{style = multiline, labelwidth = 40pt}
\begin{document}
\begin{description}
\item[Description] Returns from a function. If issued at top level, the
interpreter simply terminates, just as if end of input had been
reached.\\
\item[Return\\values]
Any arguments in effect are passed back to the caller.\\
\item[Errors] None.
\end{description}
\end{document}