如何将描述的左边距设置为 enumitem 中特定标签的宽度?

如何将描述的左边距设置为 enumitem 中特定标签的宽度?

我想制作一个带有description环境的时间表。

如果我使用以下内容:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{description}[leftmargin=*,label=0000]
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{description}

\end{document}

我收到一个错误:

ERROR: Missing control sequence inserted.

--- TeX said ---
<inserted text> 
\inaccessible 
l.7 \begin{description}[leftmargin=*]

看起来这对环境label=0000不起作用?description

如果我简单地放置leftmargin=2.8em(对于这种特殊情况),那么我就会得到我想要的:第一项的第二行与第一行对齐:

我想要得到什么

但显然我更愿意通过给出要动态测量的标签来实现这一点。

答案1

有两种方法:

\documentclass{article}
\usepackage{enumitem}
\usepackage{calc}

\begin{document}

\begin{description}[labelwidth =\widthof{\bfseries9999}, leftmargin = !]
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{description}
\bigskip

\begin{enumerate}[wide = 0pt, widest = {\bfseries9999}, leftmargin =*, font = \bfseries]
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{enumerate}

\end{document} 

在此处输入图片描述

答案2

您可以使用labeling

\documentclass{article}
\usepackage{scrextend}
\setkomafont{labelinglabel}{\bfseries}

\begin{document}

\begin{labeling}{9999}
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{labeling}

\end{document}

使用 scrextend 的结果

如果您已经使用 KOMA-Script 类,那么您可以并且应该省略包scrextend

\documentclass{scrartcl}
\setkomafont{labelinglabel}{\bfseries}

\begin{document}

\begin{labeling}{9999}
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{labeling}

\end{document}

使用 KOMA-Script 类的结果

相关内容