使用包 enumitem 的描述列表:如何强制小写字母并对齐正文?

使用包 enumitem 的描述列表:如何强制小写字母并对齐正文?

我正在尝试将标签的描述列表格式化为小写字母,并使正文与左边距保持标准距离。当我在标签中使用大写字母(在实际列表中,它们是缩写和首字母缩略词)并尝试强制使用小写字母然后使用小写字母时,我只会得到小写字母的第一个字母。此外,“leftmargin”选项似乎仅适用于有第二行的情况(即悬挂缩进)。我希望所有正文都从左边距缩进相同的量,无论标签的大小如何。

\documentclass[11pt]{memoir}   
\usepackage{enumitem}   

\begin{document}   

\begin{description}[leftmargin=4cm,font=\normalfont\scshape\MakeLowercase]   
   \item[FIRST] My definition here   
   \item[NEXT] and another one   
   \item[AFTER] This is the third   
\end{description}   

\end{document}  

答案1

要更改为小写,您可以使用before=...使用枚举项重新定义\makelabel以应用于\MakeLowercase整个标签文本:

\newcommand{\descriptionmakelabel}[1]{\scshape\MakeLowercase{#1}}
\begin{description}[before=\renewcommand{\makelabel}{\descriptionmakelabel}]

要将左边距自动设置为最大的描述标签,可以使用包等式这允许使共享相同标签的所有框具有相同的宽度(需要两次编译)。当然,您需要使 eqparbox 标签对特定描述具有唯一性,这可以使用计数器来完成。以下是完整代码及其结果:

代码结果

\documentclass[11pt]{memoir}

\usepackage{enumitem}
\usepackage{eqparbox}

\newcounter{desc}
\newcommand{\descriptionmakelabel}[1]{\eqparbox{descnb\romannumeral\value{desc}}{\scshape\MakeLowercase{#1}\hfill}}

\begin{document}

\begin{description}[before=\refstepcounter{desc}\renewcommand{\makelabel}{\descriptionmakelabel},leftmargin=\eqboxwidth{descnb\romannumeral\numexpr\value{desc}+1\relax}]
   \item[FIRST] My definition here
   \item[NEXT] and another one   
   \item[AFTER] This is the third which is very very very very very very very very very very very very very long
\end{description}

\begin{description}[before=\refstepcounter{desc}\renewcommand{\makelabel}{\descriptionmakelabel},leftmargin=\eqboxwidth{descnb\romannumeral\numexpr\value{desc}+1\relax}]
   \item[A] a short text
   \item[B] a very very very very very very very very very very very very very very very very very very very very long text
\end{description}

\end{document}

答案2

使用表格,这里更有意义:

在此处输入图片描述

\documentclass[11pt]{memoir}   
\usepackage{tabularx}   
\def\MyLowercase!#1!{\scshape\MakeLowercase{#1}}
\begin{document}   

\noindent
\begin{tabularx}{\textwidth}{@{}>{\MyLowercase!}p{4cm}<{!}X@{}}   
  FIRST & My definition here\\   
  NEXT  & and another one  and the line can be long as you like it
           there will be a linebreak if needed \\
  AFTER & This is the third   \\
\end{tabularx}   

\end{document} 

相关内容