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!

jmc
  • 1,660
  • 1
    related (but not with the specific requirement for enumitem: http://tex.stackexchange.com/questions/52715/modifying-labels-on-some-enumerated-items – egreg Mar 24 '14 at 22:26
  • @egreg — Awesome. Somehow it did not pop up out of my search. Your answer there is fabulous. – jmc Mar 25 '14 at 07:53

2 Answers2

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

  • 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 Mar 24 '14 at 17:58
  • @jmc: Regarding that extra *****: I thought you intended to so do, see your middle example in your MWE. –  Mar 24 '14 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 Mar 24 '14 at 18:03
  • @jmc: Ok, I admit: I have never used enumitem before ;-) I changed as you wished –  Mar 24 '14 at 18:05
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

egreg
  • 1,121,712
  • 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 Mar 25 '14 at 07:54