使用自定义标签进行缩进

使用自定义标签进行缩进

我需要帮助解决description使用自定义标签的列表中的缩进问题。下面的示例显示了我的问题。谢谢!

\documentclass{article}

\usepackage{enumitem}

\setlist[description]{leftmargin=\parindent}

\begin{document}

\begin{description}

\item[3.] My issue is indentation within this list.  I need the custom labels because I might have to skip numbers. This particular item is indented the way I want it, namely, the second line is aligned with the first word ``My'' of the first line.

\item[30.] Here is where the problem lies. In this item the custom label consists of two digits and a period, and as a result, the second line is no longer aligned with the first letter ``H'' of the first line.  Looks bad.

\item[Idea.] If we use the ordinary enumerate environment without custom labels, then as the labels get longer (1, 10, 100, etc.), they ``grow'' to the left rather than to the right, as my labels here are doing.  Maybe there is an easy way for me to tell my custom labels that they too should grow to the left?  If so, would that solve my indentation problem?

\end{description}

\end{document}

姆韦

答案1

你可以这个很好的答案只需改变一个字母就可以使标签右对齐:

\documentclass{article}
\usepackage{eqparbox}
\usepackage{enumitem}
\usepackage[margin=1em,papersize={4in,2.2in}]{geometry}

\newlist{mydescription}{description}{1} %% <- pick a larger number if you want to nest these
\setlist[mydescription]{
    labelwidth=\eqboxwidth{listlabel@\EnumitemId},
    leftmargin=!,
    format=\mydescriptionlabel,
}
\newcommand\mydescriptionlabel[2][r]{\eqmakebox[listlabel@\EnumitemId][#1]{#2}}  % change l to r 

\newcommand{\text}{long long long long long long long long long long
  long long long long long long long long long long long long long
  long long long long long long long text}

\begin{document}
\begin{mydescription}
\item[The longest label] text
\item[Short] \text
\end{mydescription}
\hrule
\begin{mydescription}
\item[Medium label] text
\item[Short] \text
\end{mydescription}
\end{document}

在此处输入图片描述

相关内容