17

Ok, since this question seems to be pretty easy (well I still don't know the answer and didn't find something on this site), I'll try it without MWE: I'd like to know how to change the number of items in enumerate environments. Most appreciated would be solutions without additional packages or such...

\begin{enumerate}
  \item The fifth item
  \item The seventh item
\end{enumerate}

This should result in

5. The fifth item
7. The seventh item

and not in the normal items numbered 1 and 2. It probably has to do something with counters!?

0

1 Answer 1

26
  1. Set the enumi counter and do it through a command for easiness (for a more general answer, see below):

    \documentclass{article}
    
    \newcommand\setItemnumber[1]{\setcounter{enumi}{\numexpr#1-1\relax}}
    
    \begin{document}
    
    \begin{enumerate}
      \setItemnumber{5}
      \item The fifth item
      \setItemnumber{7}
      \item The seventh item
    \end{enumerate}
    
    \end{document}
    

    enter image description here

    Since the previous definition of the command uses enumi, the defined command \setItemnumber will only work for the first level for nested enumerates. Using the \@enumdepth counter (controlling the nesting depth for enumerated lists), the command can be improved so as to be used for every level in nested enumerations:

    \documentclass{article}
    
    \makeatletter
    \newcommand\setItemnumber[1]{\setcounter{enum\romannumeral\@enumdepth}{\numexpr#1-1\relax}}
    \makeatother
    
    \begin{document}
    
    \begin{enumerate}
      \setItemnumber{5}
      \item The fifth item
      \begin{enumerate}
        \setItemnumber{3}
        \item The third subitem
        \setItemnumber{9}
        \item The ninth subitem
      \end{enumerate}
      \setItemnumber{7}
      \item The seventh item
    \end{enumerate}
    
    \end{document}
    

    The result:

    enter image description here

  2. Use the optional argument for \item (but you loose in this way the possibility to do cross-references to those items):

    \documentclass{article}
    
    \begin{document}
    
    \begin{enumerate}
      \item[5.] The fifth item
      \item[7.] The seventh item
    \end{enumerate}
    
    \end{document}
    
7
  • i know the version that adjusts the counter will work reliably with \label and \ref. will the other work as well? (i could try it, but having the answer here might help someone else too.) Commented Jul 13, 2015 at 18:23
  • @barbarabeeton No, it won't. I just added the remark. Commented Jul 13, 2015 at 18:24
  • Works, thx! :) setcounter{enumi}{x} would have done it, but your newcommand is a nice addition
    – caligula
    Commented Jul 13, 2015 at 18:24
  • @caligula You're welcome. Yes, the command is useful; using just \setcounter{enumi}{x} you would have to remember to use n-1 to get n, the command does the calculation for you :) Commented Jul 13, 2015 at 18:29
  • Ok, I found a question: What is the \relax good for?
    – caligula
    Commented Jul 13, 2015 at 18:31

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