文本格式化:使用枚举

文本格式化:使用枚举

我是 LaTex 新手,我想使用compactenumparalist包进行枚举。所以我写了以下内容:

\documentclass{article}
\usepackage{paralist}

\begin{document}
\begin{compactenum}[\mbox{FA-SWK-}1]
  \item Item one
  \item Item two
  \item Item three
  \item Item four
  \item Item five
  \item Item six
  \item Item seven
  \item Item eight
  \item Item nine
  \item Item ten
  \item Item eleven
  % and so on...
\end{compactenum}
\end{document}

现在我遇到的问题是第 10 项中的文本不对齐。实际上它看起来像这样:

FA-SWK-1 Item one
FA-SWK-2 Item two
...
FA-SWK-10 Item ten

但我希望它看起来像这样:

FA-SWK-1  Item one
FA-SWK-2  Item two
...
FA-SWK-10 Item ten

是否可以仅为前九项添加空值或更改枚举和文本之间的间距?

答案1

你可以通过以下技巧paralist为数字留出更多空间:

\documentclass{article}
\usepackage{paralist}

\protected\def\double#1\double{\makebox[1em][l]{#1}}

\begin{document}

\begin{compactenum}[\mbox{FA-SWK-}\double1\double]
  \item Item one
  \item Item two
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
\end{compactenum}

\end{document}

enumitem

\documentclass{article}
\usepackage{enumitem}

\newcommand{\boxedarabic}[1]{\makebox[1em][l]{\arabic#1}}

\begin{document}

\begin{enumerate}[label=FA-SWK-\boxedarabic*,nosep]
  \item Item one
  \item Item two
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
\end{enumerate}

\end{document}

在此处输入图片描述

答案2

带有 的变体enumitem,使用widest密钥:

\documentclass{article}
\usepackage{enumitem}
\newlength\mylabelwd
\settowidth{\mylabelwd}{FA-SWK-999}

\begin{document}

Some text some text some text some text some text some text some text some text some text some text some text.
\begin{enumerate}[label=FA-SWK-\arabic*, widest =999, align=left, labelindent=\parindent, leftmargin=\dimexpr\mylabelwd+\labelindent+\labelsep\relax, itemindent=*, noitemsep]
  \item Item one
  \item Item two
  \item Item three and so on. Item three and so on. Item three and so on. Item three and so on.
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
  \item Item three and so on
\end{enumerate}

\end{document}

在此处输入图片描述

答案3

您可以使用以下方法\phantom来创建角色:

\begin{compactenum}[\text{FA-SWK-}1]
  \item \leavevmode\hphantom{0}one 
  \item \leavevmode\hphantom{0}two 
  \item \leavevmode\hphantom{0}three and so on 
  % Some other \item
  \item FA-SWK-10 ten
\end{compactenum}

它创建了一个不可见的字符,其大小与空间相同。(由于我使用的计算机,无法显示结果)

相关内容