Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I add leading zeros in the items that are listed by the packages etaremune and enumerate? For example, I would like to have the labels to be:

A01, A02, A03, ..., A09, A10

Here is an example code. How can I add the leading zeros locally and globally?

\documentclass{article}

\usepackage{etaremune}
\usepackage{enumitem}
\setlist[enumerate]{nosep} % To remove the spacing


\begin{document}
First list

\renewcommand*{\labelenumi}{A\theenumi.}
\begin{etaremune}[topsep=0pt,itemsep=0pt,partopsep=0pt,parsep=0pt,] 
    \item item 10
    \item item 09
    \item item 08
    \item item 07
    \item item 06
    \item item 05
    \item item 04
    \item item 03
    \item item 02
    \item item 01
\end{etaremune}

Second list
\begin{enumerate}[label={M\arabic*.}]
    \item item 01
    \item item 02
\end{enumerate}

Third list
\begin{enumerate}[label={M\arabic*.}, resume]
    \item item 03
    \item item 04
\end{enumerate}

\end{document}

Here is enter image description herethe output:

share|improve this question

1 Answer 1

[Edit I'm editting this to make the solution clearer, inlight of the evolution of the both the question and its solution. As a result, the comments below may not make much sense...]

The code below makes it possible to do what you want using just the enumitem package. In particular, etaremune is no longer needed because we trick enumerate into behaving like an etaremune environment using enumitem.

The code uses enumitem's \AddEnumerateCounter command to define two new counters: \PaddingUp and \PaddingDown. Both counters pad item numbers with a 0 if the counter is less than 10. The \PaddingDown counter has the extra feature of surreptitiously decreasing the item counter by one (it actually decreases it by two so that when the counter is next incremented the net effect is that it will have decreased by one).

The \PaddingUp and \PaddingDown counters can be used like any of the standard enumitem counter macros. Consequently,

\begin{enumerate}[label=Up\PaddingUp*.]
...
\end{enumerate}

creates an enumerate environment with item labels Up01., Up02., ... whereas

\begin{enumerate}[label=Down\PaddingDown*.,start=10]
...
\end{enumerate}

creates an enumerate environment with item labels Down10., Down09., ...

The following code prodcuces the OP's requested output:

\documentclass{article}
\usepackage{enumitem}

\makeatletter
\AddEnumerateCounter{\PaddingUp}{\two@digits}{A00}
\AddEnumerateCounter{\PaddingDown}{\two@digits}{A00}
\newcommand\PaddingUp[1]{\expandafter\two@digits\csname c@#1\endcsname}
\newcommand\PaddingDown[1]{\PaddingUp{#1}\addtocounter{#1}{-2}}
\makeatother

\setlist[enumerate]{nosep,label=M\PaddingUp*.} % To remove the spacing
\newlist{etaremune}{enumerate}{1}% one level of nesting
\setlist[etaremune]{nosep,label=A\PaddingDown*.}

\begin{document}

First list
\begin{etaremune}[start=10]
    \item item 10
    \item item 09
    \item item 08
    \item item 07
    \item item 06
    \item item 05
    \item item 04
    \item item 03
    \item item 02
    \item item 01
\end{etaremune}

Second list
\begin{enumerate}
    \item item 01
    \item item 02
\end{enumerate}

Third list
\begin{enumerate}[resume]
    \item item 03
    \item item 04
\end{enumerate}

\end{document}

For good measure, the code above defines an etaremune enviroment with the nosep option. This is possibly misleading, however, because the decreasing counters are given by setting the label to label=\PaddingDown*. Above, this is done using setlist. Note that it is necessay to explicitly set the starting value of the item counters in an etaremune environment. If you don't set a starting value then they will start from 1, which is probably not what you want.

Finally, perhaps I should point out that it is easy to change the letters etc labelling these environments as you use them. For example, to change them to use P's and Q's you would write:

\begin{enumerate}[label=P\PaddingDown*.]% item -> P#. going up
    \item item 01 \item item 02
\end{enumerate}

\begin{enumerate}[label=Q\PaddingUp*.]% item -> P#. going down
    \item item 01 \item item 02
\end{enumerate}
share|improve this answer
    
Thanks. It works perfectly. How can I do the same thing for enumerate? The code you kindly posted only works for etaremune and the ones in my document that are using enumerate are intact and no leading zeros are printed. Can this be modified such that it works for enumerate as well: \begin{enumerate}[label={M\arabic*.},] \item item 01 \item item 02 \end{enumerate} –  A2009 Aug 4 at 3:19
    
@A2009 Actually, this is a "bug" in my fix in that it will also modify how the counters are printed in an enumerate environment. Luckily you want this! To have this work you need to put the \renewcommand\theenumi... in your preamble at the top of your document. I think that the eumerate environments for which this is failing must be before this commend in your document. Is this correct? –  Andrew Aug 4 at 3:28
    
Actually, it is already at the top of the document. –  A2009 Aug 4 at 3:30
    
Oh, I see from your comment that you must be using the enumitem package, so the reason why this doesn't work is that the label={M\arabic*.} is redefining the labels...will see if there is a good way to get this to work in the enumitem framework. –  Andrew Aug 4 at 3:33
1  
If you only want your modified \theenumi to have an effect locally, place it in the environment before for the first \item. –  A.Ellett Aug 4 at 3:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.