diff --git a/enumitem.pdf b/enumitem.pdf index fcbca83..2f6a4f7 100644 Binary files a/enumitem.pdf and b/enumitem.pdf differ diff --git a/enumitem.sty b/enumitem.sty index 1cb7888..d93c071 100644 --- a/enumitem.sty +++ b/enumitem.sty @@ -12,6 +12,8 @@ \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{enumitem}[2019/06/20 v3.9 Customized lists] +\RequirePackage{eqparbox}% Needed by autowidest + % Notes % ~~~~~ % @@ -145,6 +147,7 @@ \newif\ifenit@sepfrommargin \newif\ifenit@lblfrommargin \newif\ifenit@calcwidest +\newif\ifenit@autowidest \newif\ifenit@nextline \newif\ifenit@boxdesc @@ -277,6 +280,7 @@ \fi\fi} \def\enitkv@enumitem@widest#1{% + \enit@autowidestfalse% Manually using widest overrides autowidest \ifcase\enit@type % enumerate \expandafter\let\csname enit@cw@\@enumctr\endcsname\relax \@namedef{enit@widest@\@enumctr}##1{\enit@format{#1}}% @@ -289,12 +293,34 @@ \expandafter\let\csname enit@widest@\@enumctr\endcsname\relax} \enitkv@key{}{widest*}{% + \enit@autowidestfalse% Manually using widest* overrides autowidest \setcounter{enit@cnt}{#1}% \expandafter\edef\csname enit@cw@\@enumctr\endcsname {\the\c@enit@cnt}% \expandafter\edef\csname enit@widest@\@enumctr\endcsname##1% {##1{\the\c@enit@cnt}}} +\enitkv@key{}{autowidest}[]{% + % \eqboxwidth gets the widest width of the calls to \eqp@compute@width with the same argument + \enitkv@setkeys{widest}{\hbox to \eqboxwidth{enit@autowidest@\EnumitemId}{}} + \enit@autowidesttrue} +% \enit@autowidest needs to be called after \makelabel is set up properly +% (thus it is not called as part of \enit@calcleft since that gets called in the wrong place for descriptions) +\newcommand\enit@autowidest{% + \ifenit@autowidest\ifenit@calcwidest% autowidest only makes sense if used with an =* option + \let\enit@makelabel=\makelabel% Save the original \makelabel + % Override \makelabel so that it also keeps track of label widths + \def\makelabel##1{ + \savebox\enit@inbox{\enit@makelabel{#1}}% Stop \eqp@compute@width from typseting this twice + % \eqp@compute@width will compute the widest width by typesting \usebox\enit@inbox + % and then returns \eqp@produce@box{}{\usebox\enit@inbox} + % \eqp@produce@box is globally defined by each of eqparbox's various \eq commands so it's safe to modify + % It's modified below to simply ignored the , as this will be handled by the + % widest key itself + \global\let\eqp@produce@box=\@secondoftwo% + \eqp@compute@width{enit@autowidest@\EnumitemId}{\usebox\enit@inbox}} + \fi\fi} + \enitkv@key{}{labelindent*}{% \enit@lblfrommargintrue \ifnum\enit@calc=\z@ @@ -936,6 +962,7 @@ \enit@tagid \enit@sepfrommarginfalse \enit@calcwidestfalse + \enit@autowidestfalse \let\enit@widest@\relax \let\enit@resuming\z@ \let\enit@series\relax @@ -1376,6 +1403,7 @@ \enit@normlabel\@itemlabel\@itemlabel \enit@ref \enit@calcleft + \enit@autowidest \enit@before \enit@negwidth}% \enit@keyfirst @@ -1413,6 +1441,7 @@ \def\makelabel##1{\enit@align{\enit@format{##1}}}% \enit@preset{#2}{#1}{#4}% \enit@calcleft + \enit@autowidest \enit@before \enit@negwidth}% \enit@keyfirst @@ -1461,6 +1490,7 @@ \enit@svlabel{\enit@format{##1}}% \aftergroup\enit@postlabel \fi}% + \enit@autowidest% This needs to go after the \makelabel definition above \enit@before \enit@negwidth}% \enit@keyfirst diff --git a/enumitem.tex b/enumitem.tex index 9484acd..88b92a8 100644 --- a/enumitem.tex +++ b/enumitem.tex @@ -21,6 +21,7 @@ \definecolor{notes}{rgb}{.75, .3, .3}% \makeatletter +\expandafter\def\csname ver@array.sty\endcsname{} % Because it's loaded by eqparbox but breaks the decl environment \newenvironment{desc} {\if@nobreak \vskip-\lastskip @@ -573,7 +574,7 @@ \subsection{Horizontal spacing of labels} \end{note} \begin{desc} -|widest=|\qquad|widest*=|\qquad|widest| +|widest=|\qquad|widest*=|\qquad|widest|\qquad|autowidest| \end{desc} To be used in conjunction with the \texttt{*}-values, if desired. It @@ -597,6 +598,9 @@ \subsection{Horizontal spacing of labels} you might need change the computed parameter (eg, |itemindent=*| with |align=left|). +\New{3.X} You can use |autowidest| to have \textsf{enumitem} +work out the actual widest label for you, however it requires at least two runs of \LaTeX. + \begin{desc} |labelsep*=| \end{desc} @@ -863,21 +867,7 @@ \subsection{Injecting code} assigned to each list, returned by |\EnumitemId|. \begin{example} - Here is an example of how to combine a |\label| with |\EnumitemId|, - and |after| to automatically set the width of the list label to the - widest one (provided the ref is the same as the label):\footnote{See - \texttt{https://tex.stackexchange.com/questions/29322/% - how-to-make-enumerate-items-align-at-left-margin}.} -\begin{verbatim} -\SetEnumitemKey{widestlabel} - {labelwidth = \widthof{\ref{enum-\EnumitemId}}, - after = \label{enum-\EnumitemId}} -\end{verbatim} -Then just use the key |widestlabel|. -\end{example} - -\begin{example} - Reverse counting is also doable, but somewhat trickier, and we need + Here is an example of reverse counting, but it is somewhat tricky, and we need some ``external'' help. Here is a possible solution, but not the only one (and very likely not even the best -- for example, |start| is in fact no-op).