我需要以这样一种方式使用描述环境,这样我就不必一遍又一遍地写交替标签(如下例所示)。有没有办法让这些标签自动生成?这将节省大量时间和麻烦。谢谢。
\begin{description}
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\end{description}
答案1
基于enumerate
环境的变体,具有enumitem
和etoolbox
:
\documentclass{article}
\usepackage{enumitem}
\usepackage{etoolbox}
\newlist{alternate}{enumerate}{1}
\renewcommand\labelalternatei{\bfseries\protect\ifnumodd{\value{alternatei}}{A:}{B:}}
\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 some text.
\begin{alternate}[wide=0pt]
\item First
\item Second
\item Third
\item Fourth
\item Fifth
\item Sixth
\end{alternate}
\end{document}
答案2
借助包裹enumitem
和一些我无法解释的黑魔法。
\documentclass{article}
\usepackage{enumitem}
\protected\def\mylabel#1{\ifodd#1A:\else B:\fi}
\AtBeginDocument{\sbox0{\bfseries A:\hspace\labelsep}%
%\edef\Ahmad{\dimexpr\number\wd0 sp\relax}% pleasing but slower
\edef\Ahmad{\the\wd0}%
}
\begin{document}
\begin{enumerate}[label=\bfseries\mylabel{\value*},
itemindent=\dimexpr-\leftmargin+\Ahmad\relax,
labelwidth=\Ahmad]
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\end{enumerate}
\begin{description}
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\end{description}
\end{document}