31

I want to change the label of one item in a list. I am using the enumitem package, I am very fond of it, and I have to keep using it (lots of other code would break).

MWE:

\documentclass[a4paper,10pt]{article}

\usepackage[]{enumitem}

\begin{document}
Foobar

\begin{enumerate}[label={(\arabic*)}]
        \item baz
\end{enumerate}
\begin{enumerate}[resume,label={(*\arabic*)}]
        \item xyzzy
\end{enumerate}
\begin{enumerate}[resume,label={(\arabic*)}]
        \item quux
\end{enumerate}

Lorem ipsum
\end{document}

The result is a list

 (1) baz
(*2) xyzzy
 (3) quux

However, I would like to do something like

\documentclass[a4paper,10pt]{article}

\usepackage[]{enumitem}

\begin{document}
Foobar

\begin{enumerate}[label={(\arabic*)}]
        \item baz
        \staritem xyzzy
        \item quux
\end{enumerate}

Lorem ipsum
\end{document}

It would be very cool if the enumitem package would make code like \item[label=(*\arabic*)] possible. But as far as I know, an easy solution is not available.

What would you do? Please define a command \staritem in your answer, as this would be a more orthogonal solution than hacking it straight into the document text. Alternatively, hacking \item to accept options (as in \item[label=(*\arabic*)]) would be awesome!

2
  • 1
    related (but not with the specific requirement for enumitem: tex.stackexchange.com/questions/52715/…
    – egreg
    Commented Mar 24, 2014 at 22:26
  • @egreg — Awesome. Somehow it did not pop up out of my search. Your answer there is fabulous.
    – jmc
    Commented Mar 25, 2014 at 7:53

2 Answers 2

23

Put the asterisk in the specification of the label:

\documentclass[a4paper,10pt]{article}

\usepackage{enumitem}

\newcommand{\staritem}{\global\asterisktrue\item}
\newcommand{\perhapsasterisk}{%
  \ifasterisk*\global\asteriskfalse\fi
}
\newif\ifasterisk

\begin{document}
Foobar

\begin{enumerate}[label={(\protect\perhapsasterisk\arabic*)}]
\item baz
\staritem xyzzy
\item quux
\staritem xxx
\end{enumerate}

Lorem ipsum
\end{document}

enter image description here

1
  • 1
    Wonderful answer, because (i) this easily generalises to nested lists, and (ii) changing the format of labels now only needs to happen in one place.
    – jmc
    Commented Mar 25, 2014 at 7:54
26

I am not sure whether this is, what you want to achieve, but you can explicitly set the label of an item.

\documentclass[a4paper,10pt]{article}

\usepackage{enumitem}


\begin{document}
Foobar

\begin{enumerate}[label={(\arabic*)}]
        \item baz
        \item[\refstepcounter{enumi}(*\number\value{enumi})] xyzzy
        \item quux
\end{enumerate}

Lorem ipsum
\end{document}

I suppose, the \refstepcounter statement inside the [] is necessary because the counter is not advanced if one sets the label by hand.

enter image description here

4
  • Awesome, thanks. In the end it was easier than I thought. I don't know why I didn't try this combo. (I was trying to difficult stuff, somewhere in the internals of enumitem.) Note that you have one * too much. In the end I did \def\staritem{\refstepcounter{enumi}\item[(*\number\value{enumi})]}. Would you mind to edit this into your answer?
    – jmc
    Commented Mar 24, 2014 at 17:58
  • @jmc: Regarding that extra *****: I thought you intended to so do, see your middle example in your MWE.
    – user31729
    Commented Mar 24, 2014 at 18:01
  • The example only has a * in front of the digit. In the code it reads *\arabic*, but the latter * is part of the enumitem syntax.
    – jmc
    Commented Mar 24, 2014 at 18:03
  • @jmc: Ok, I admit: I have never used enumitem before ;-) I changed as you wished
    – user31729
    Commented Mar 24, 2014 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .