5

I'm trying to resume a list by storing and restoring the counter. This works fine (as described here), but I fail to do it for a nested list. Here's my code:

\documentclass{article}

\usepackage{multicol}

\begin{document}

  \newcounter{stoppedhere}

%   \begin{enumerate}      % <- outer list commented out
%     \item Outer list

    \begin{multicols}{3}
      \begin{enumerate}
        \item $e$
        \item $\gamma$
        \item $\mu$
        \item $p$
        \item $n$
        \item $\pi^+$
        \item $\pi^0$
        \item $\nu_\mu$
        \setcounter{stoppedhere}{\theenumi}
      \end{enumerate}
    \end{multicols}
    \begin{enumerate}
      \setcounter{enumi}{\thestoppedhere}
      \item much longer item 1
      \item another much longer item
    \end{enumerate}

%   \end{enumerate}

\end{document}

The code above first lists 1. - 9. and then continues with 10., so that works.

Now if I add back the outer list, the resumed list starts with the wrong value (as expected). I thought I could solve this by using enumii, but trying to do

\setcounter{stoppedhere}{\theenumii}

gives an error (! Missing number, treated as zero.). What need I do instead?

(The multicol environment is not part of the problem, unless I try to use the package enumitem instead of modifying the counters myself: then it only works without the multicol environment.)

  • Use enumitem. Then you can use resume to continue an enumerated list. – cfr Jun 27 '15 at 16:31
  • @cfr: I thought that too, but the multicols environment does indeed work badly here –  Jun 27 '15 at 16:33
  • @ChristianHupfer I don't think it is really multicols fault.... – cfr Jun 27 '15 at 16:46
  • @cfr: No, it's rather a grouping/nesting problem. Apparently enumitem loses the track which nesting level was valid –  Jun 27 '15 at 16:48

2 Answers2

6

There are two ways:

  1. Use the counter method with enumitem and manually add a start=... to the next enumeration
  2. Use the enumitem package and define the inner list as a series innerlist (the name is rather arbitrary) and useresume=innerlistin the continued (outside ofmulticols` environment) list. This is the better way, in my point of view (see example at the bottom of this post)

Note: \theenumi should not be used as argument to \setcounter, since \theenumi could be defined to be anything, letters, brackets with letters, numbers etc. Use \value{enumi} for a pure number.


\documentclass{article}

\usepackage{multicol}

\usepackage{enumitem}
\newcounter{stoppedhere}

\begin{document}
   \begin{enumerate}      % <- outer list commented out
     \item Outer list
       \begin{multicols}{3}
         \begin{enumerate}
         \item $e$
         \item $\gamma$
         \item $\mu$
         \item $p$
         \item $n$
         \item $\pi^+$
         \item $\pi^0$
         \item $\nu_\mu$
           \setcounter{stoppedhere}{\value{enumii}}
         \end{enumerate}
    \end{multicols}
    \begin{enumerate}[start=\numexpr\number\value{stoppedhere}+1]
      \item much longer item 1
      \item another much longer item
    \end{enumerate}
   \end{enumerate}
\end{document}

Other approach: (Better!)

\documentclass{article}

\usepackage{multicol}

\usepackage{enumitem}

\begin{document}
   \begin{enumerate}      % <- outer list commented out
     \item Outer list
       \begin{multicols}{3}
         \begin{enumerate}[series=innerlist]
         \item $e$
         \item $\gamma$
         \item $\mu$
         \item $p$
         \item $n$
         \item $\pi^+$
         \item $\pi^0$
         \item $\nu_\mu$
         \end{enumerate}
    \end{multicols}
    \begin{enumerate}[resume=innerlist]
      \item much longer item 1
      \item another much longer item
    \end{enumerate}
   \end{enumerate}
\end{document}

enter image description here

  • 1
    You might add the explanation: \theenumii produces a letter rather than a number. – cfr Jun 27 '15 at 16:43
  • @cfr: I am about completing the answer ... just be patient ;-) –  Jun 27 '15 at 16:44
  • Thanks, this was the hint I needed. It works by just adding the \value macro. (The series thing didn't work for me, maybe my version of the enumitem package is too old.) – fuenfundachtzig Jun 27 '15 at 16:45
  • @fuenfundachtzig: Yes, it works with the counter way, but I don't recommend it. You should update enumitem. It's a very powerful package! –  Jun 27 '15 at 16:47
4

Here's a solution without enumitem. \theenumii does not produce a number so you cannot use it to set the counter. Instead, you need to use \value{enumii} which always gives the value of the counter i.e. as a number.

\documentclass{article}

\usepackage{multicol}

\begin{document}

  \newcounter{stoppedhere}

  \begin{enumerate}      % <- outer list commented out
    \item Outer list

    \begin{multicols}{3}
      \begin{enumerate}
        \item $e$
        \item $\gamma$
        \item $\mu$
        \item $p$
        \item $n$
        \item $\pi^+$
        \item $\pi^0$
        \item $\nu_\mu$
        \setcounter{stoppedhere}{\value{enumii}}
      \end{enumerate}
    \end{multicols}
    \begin{enumerate}
      \setcounter{enumii}{\thestoppedhere}
      \item much longer item 1
      \item another much longer item
    \end{enumerate}

  \end{enumerate}

\end{document}

inner and outer

cfr
  • 198,882