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.

In an enumerate environment, I want a few (not all) of the items to have asterisks which appear before the number (I don't feel strongly about whether the number or the asterisk is horizontally aligned with the other numbers). Is there a less crufty way to do this than, say, using multiple lists (or — horrors — numbering manually)?

I'm already using enumitem for an unrelated purpose, if that helps, although I didn't find a solution after a quick skim of its manual.

share|improve this question
    
Is the number of asterisks variable or is it always the same number independently of the item number? –  Gonzalo Medina Apr 20 '12 at 17:11
    
Always the same and always one; sorry, I wasn't very clear. –  Mark Meckes Apr 20 '12 at 17:15
add comment

2 Answers 2

up vote 24 down vote accepted

How about this

enter image description here

\documentclass{article}
\newcommand{\myitem}{\stepcounter{enumi}\item[$*$\theenumi.]}

\begin{document}
\begin{enumerate}
 \myitem first 
 \item second
 \item third
 \myitem fourth
\end{enumerate}
\end{document}
share|improve this answer
3  
I'm not sure whether this is relevant, but this way the * will not be part of a reference to the item. –  Stephan Lehmke Apr 20 '12 at 17:14
    
Fortunately I don't need to make any references to the list items. –  Mark Meckes Apr 20 '12 at 17:16
    
I'm accepting this right away partly because I'm amused at how well it confirmed my feeling that there may be a really easy solution which I could find more quickly using this site than thinking about it myself. Nevertheless, I'd be interested to see others. –  Mark Meckes Apr 20 '12 at 17:18
    
@cmhughes -- the asterisk might show up a bit more prominently if the digits were aligned. for that, just add the (default) period after \theenumi: \newcommand{\myitem}{\stepcounter{enumi}\item[$*$\theenumi.]} –  barbara beeton Apr 20 '12 at 17:26
    
@barbarabeeton good idea, thanks- see edit –  cmhughes Apr 20 '12 at 18:10
add comment

Redefine momentarily \labelenumi (it's a bit more difficult if you want it for any nesting level). It works also with \label, but the asterisk won't be part of the reference.

\documentclass{article}
\def\asteriskitem{*\,}
\def\sitem{%
  \let\originallabelenumi\labelenumi
  \expandafter\def\expandafter\labelenumi\expandafter{%
    \expandafter\asteriskitem\labelenumi}%
  \item
  \let\labelenumi\originallabelenumi
}

\begin{document}
\begin{enumerate}
\item a
\sitem b
\item c
\end{enumerate}
\end{document}

enter image description here

Just for the record, here is something that should work with every nesting level:

\makeatletter
\def\sitem{%
  \expandafter\let\expandafter\originallabel\csname labelenum\romannumeral\@enumdepth\endcsname
  \expandafter\def\csname labelenum\romannumeral\@enumdepth\expandafter\endcsname\expandafter{%
    \expandafter\asteriskitem\originallabel}%
  \item
  \expandafter\let\csname labelenum\romannumeral\@enumdepth\endcsname\originallabel
}
\makeatother

Explanation

Let's see how the simpler solution works. To begin with, we have to know that \item uses \labelenumi for typesetting the first level numbers, and that it is a parameterless macro.

We want to change the meaning of \labelenumi so that it typesets also the asterisk, so we define a macro for the asterisk and a small space; then we define a command \sitem that changes the definition, issues \item and restores the original \labelenumi. The "easy" method for doing this, that is, changing the definition in a group, doesn't unfortunately work. So we save the original meaning in \originallabelenumi and do

\expandafter\def\expandafter\labelenumi\expandafter{%
  \expandafter\asteriskitem\labelenumi}%

The first \expandafter activates all the following ones, so that the expansion of \labelenumi is obtained before \def acts (the fact that \labelenumi has no arguments is very important here).

The general solution is very similar, but requires knowing something more about enumerate. The nesting level is accessible through the value of \@enumdepth, which is a "TeX counter"; with \romannumeral\@enumdepth we can thus refer to the right LaTeX macro \labelenumi, \labelenumii, \labelenumiii or \labelenumiv with \csname labelenum\romannumeral\@enumdepth\endcsname.

Therefore we save the meaning of the right macro with

\expandafter\let\expandafter\originallabel\csname labelenum\romannumeral\@enumdepth\endcsname

With etoolbox this might become

\letcs\originallabel{labelenum\romannumeral\@enumdepth}

Getting the expansion of \originallabel is done essentially as before:

\expandafter\def\csname labelenum\romannumeral\@enumdepth\expandafter\endcsname\expandafter{%
  \expandafter\asteriskitem\originallabel}

but using a slick trick. The first \expandafter triggers \csname, which expands everything it finds up to the matching \endcsname, including the inner \expandafter which triggers the following ones. Finally the right token (say \labelenumi if the value of \@enumdepth is 1) is put after \def and TeX would see the correct command among

\def\labelenumi{\asterisk<expansion of \originallabel>}
\def\labelenumii{\asterisk<expansion of \originallabel>}
\def\labelenumiii{\asterisk<expansion of \originallabel>}
\def\labelenumiv{\asterisk<expansion of \originallabel>}

according to the value of \@enumdepth, as desired. After issuing \item, the meaning of \labelenum?? is restored.

share|improve this answer
1  
+1 +1 +1 :-) very nice solution –  Marco Daniel Apr 20 '12 at 18:11
1  
+1 wonderful answer! I plan to study it in the hope of gaining a better understanding of \expandafter –  cmhughes Apr 21 '12 at 10:31
    
@cmhughes I've added some explanations. –  egreg Apr 21 '12 at 10:52
add comment

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.