244

I'd like to be able to resume an enumerated list, continuing the old numbering, after some intervening text which should not be formatted like a list item. Is there a nice way to do this?

In particular, I don't want to start a second list with a hard-coded initial counter value, because that will break if I change the number of items in the first list.

Juan A. Navarro
  • 62,139
  • 32
  • 140
  • 169
Mark Meckes
  • 17,791

6 Answers6

262

This can easily be done using the enumitem package, for example:

\documentclass[12pt]{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
  \item One
  \item Two
  \end{enumerate}
Some text
\begin{enumerate}[resume]
  \item Three
\end{enumerate}
\end{document} 

Output:

alt text

If you use \usepackage[shortlabels]{enumitem} and have configured labels (e.g., using \begin{enumerate}[(1)]), you can carry over this formatting by using [resume*].

Alternatively, the package mdwlist provides the commands \suspend and \resume for temporarily ending a list and restarting it.

Stefan Kottwitz
  • 231,401
142

Just save the counter and then restore it. There's no reason to use packages for things like this.

\documentclass{article}

\newcounter{nameOfYourChoice}

\begin{document}

\begin{enumerate}
\item Foo
\setcounter{nameOfYourChoice}{\value{enumi}}
\end{enumerate}

Foo

\begin{enumerate}
\setcounter{enumi}{\value{nameOfYourChoice}}
\item Foo
\end{enumerate}

\end{document}
rocarvaj
  • 153
Carl Mummert
  • 1,974
  • 11
    I admire the simplicity. The advantage of one of the packages Stefan suggested is that it allows for more semantic markup. – Mark Meckes Aug 14 '10 at 13:22
  • 15
    I'm happy to see this solution. I'm always a bit hesitant to clutter my document with yet another package, because you can never really be sure what else it does under the hood, in addition to fixing a small problem you have. – Thomas Feb 08 '11 at 16:23
  • 3
    I think this is the better solution for a one off. But if you're going to be doing it a lot, then the enumitem solution is better (especially since you might want to use other features of enumitem if you have a lot of lists going on...) – Seamus May 30 '11 at 12:50
  • 8
    Thinking about it, this solution also has the advantage that you can have one list, then have another list, and then resume the first list. (Although I'm not totally sure that would be a good idea...) – Seamus May 30 '11 at 12:56
  • 5
    @Seamus: Apparently enumitem also allows one to do that, through what it calls series. – Mark Meckes Apr 20 '12 at 16:54
  • 2
    This didn't work for me. I had to write \setcounter{nameOfYourChoice}{\value{enumi}}, etc. – Jonathan Wise May 17 '15 at 20:40
  • 3
    For those frustrated with how the enumitem package plays with Beamer (not well), this is a great solution. – Shane Jun 22 '16 at 05:04
  • using [resume] option didn't work for me, when referencing the numbers (the relative value would be returned, not the resumed value). This solved my issue. Thanks. – Nicholas Hamilton Mar 13 '17 at 08:50
  • just avoid the hesitations, \newcounter{nameOfYourChoice} will work outside preamble as well (I found easier to follow my counter in that way). I am not aware of that if it is bad for anything else. – trblnc Aug 07 '17 at 14:18
  • great solution! i was having problems figuring out enumitem :) – Aerinmund Fagelson Sep 13 '17 at 10:57
  • Niether the old solution, nor the new solution, works for me. Either way the setcounter in the second enumerate says the counter that was set earlier (in first enumerate) is not defined. – Caleb Stanford Nov 08 '17 at 19:09
  • @6005: I just now copied the exact document from the answer and it compiled correctly. So I cannot say what is causing the error you are seeing. – Carl Mummert Nov 08 '17 at 20:08
  • @CarlMummert Thanks for checking! Probably something to do with all the customization in my document. I figured it out a different way. – Caleb Stanford Nov 09 '17 at 06:08
  • This solution works quite well for resuming a list when each enumerate environment is in a different beamer block. – Waldir Leoncio May 09 '18 at 12:25
  • Thank you @CarlMummert! The success of this solution for my book chapters was immediate. I had no success in getting enumitem to cooperate. First the pdf instructions need a makeover. When users have simple questions such as "how can I control numbering from section to section or chapter to chapter? if the solution requires more than the most obvious commands, then the authors need to map out appropriate steps.I appreciate the great work that the mods do here and their feedback. All the best. – afrothetics Dec 17 '21 at 17:53
  • nameOfYourChoice is now the name of my choice :-D – Joanna Bryson Nov 07 '22 at 11:13
25

The question How to have the same counter in two enumerate lists? was closed as a duplicate of this one but introduced a slight difference: one of the pieces of the enumeration was inside a theorem environment. When using enumitem this needs special handling. The solution is contained in Mark Meckes comment on Carl's answer above, but in light of the new question I thought it instructive to give an example.

First, the non-working code:

\documentclass{article}
\usepackage{enumitem}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem} We are in the theorem environment,
\begin{enumerate}
\item\label{condition1}the first condition,
\item\label{condition2}the second condition,
\end{enumerate}
\end{theorem}

We have exited the theorem environment. We also have one more condition,

\begin{enumerate}[resume]
\item\label{condition3}\emph{the third condition}.
\end{enumerate}
\end{document}

When TeXed, the third condition has the incorrect number 1. Commenting out the \begin{theorem} and \end{theorem} lines gives it the correct number 3.

The correct way to correct this is to use the series key. This is explained in Section 3.5 of the enumitem manual. The feature was introduced in Version 3.0.

\documentclass{article}
\usepackage{enumitem}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem} We are in the theorem environment,
\begin{enumerate}[series=theoremconditions]
\item\label{condition1}the first condition,
\item\label{condition2}the second condition,
\end{enumerate}
\end{theorem}

We have exited the theorem environment. We also have one more condition,

\begin{enumerate}[resume=theoremconditions]
\item\label{condition3}\emph{the third condition}.
\end{enumerate}
\end{document}

This produces the correct numbering. It can also handle having arbitrary stuff in between, including other lists.

Here's the same example with the labels modified (see How to have the same counter in two enumerate lists?), also showing the use of the resume* variant.

\documentclass{article}
\usepackage{enumitem}
\newtheorem{theorem}{Theorem}

\begin{document}
\begin{theorem} We are in the theorem environment,
  \begin{enumerate}[label=(\roman*),series=theoremconditions]
    \item \label{condition1}the first condition,
    \item \label{condition2}the second condition,
  \end{enumerate}
\end{theorem}

We havve exited the theorem environment. We also have one more condition,
\begin{enumerate}[resume*=theoremconditions]
  \item \label{condition3}\emph{the third condition}
\end{enumerate}

\begin{theorem}
  We have another theorem, based on \ref{condition3}.
\end{theorem}
\end{document}
Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
  • Interestingly, this fix does not seem to work if your document is an amsart document. However, if this is so then Carl Mummert's \newcounter method does the trick (even with the specific conditions in your answer)! – user1729 Jun 12 '12 at 16:23
12

Here is a way if you don't want to do it by hand each time. We define a counter and make our own enumerate environment that uses that counter and doesn't reset it when we exit:

\documentclass{article}

\newcounter{myenumi} \setcounter{myenumi}{0}

\newenvironment{myenumerate}{ \begin{enumerate} \setcounter{enumi}{\value{myenumi}} }{ \setcounter{myenumi}{\value{enumi}} \end{enumerate} }

\begin{document}

\begin{myenumerate} \item first one \item second one \end{myenumerate} Now we've ended the enumeration.

Let's start enumerating again \begin{myenumerate} \item third \item fourth. \end{myenumerate} We've ended again.

But we aren't done yet \begin{myenumerate} \item fifth \item sixth \end{myenumerate} Shall we go on further? \end{document}

But - if you want to start over, then you'll need to do \setcounter{myenumi}{0} again.

In my own writing of problem sets, I have myenumerate which resets the counter each time, and another environment continuemyenumerate which doesn't reset the counter so it starts from where the last myenumerate or continuemyenumerate left off. For example:

\newcounter{myenumi}
\setcounter{myenumi}{0}

\newenvironment{myenumerate}{ \setcounter{myenumi}{0} \begin{enumerate} \setcounter{enumi}{\value{myenumi}} }{ \setcounter{myenumi}{\value{enumi}} \end{enumerate} }

\newenvironment{continuemyenumerate}{ \begin{enumerate} \setcounter{enumi}{\value{myenumi}} }{ \setcounter{myenumi}{\value{enumi}} \end{enumerate} }

Then I do

\begin{myenumerate}
   \item this is item 1
   \item this is item 2
\end{myenumerate}
Here is some text that I don't want to be in my list.
\begin{continuemyenumerate}
   \item this is item 3
\end{continuemyenumerate}
I could repeat this for more items if I wanted.

\begin{myenumerate} \item This is back to item 1 \end{myenumerate}

Joel
  • 2,429
1

A simple alternative way to do this is with the outlines package. With the outlines package, you can have a list with 4 levels of enumeration as well as a 0th layer of regular text. The levels are referenced by \0, \1, \2, \3 and \4 from plain text to most indented.

\documentclass[12pt]{article}
\usepackage{outlines}
\begin{document}
\begin{outline}[enumerate]
\1 One
\1 Two
\0 Some text
\1 Three
\2 Sub-point to three
\1 Four
\end{outline}
\end{document} 

In order to count over the zero level, a little extra work is needed. We will define a new counter to keep track of the number of items in our ordered list, for any depth. The environment where this happens is called cenumerate-- as in, continuing to enumerate. To employ this environment at any level k in i, ii, iii or iv, just employ the command \renewcommand{outlinek}{cenumerate} before the start of your outline. Be warned, this will even continue to count across outlines! To reset the counter and return to default behavior, use the command \renewcommand{outlinek}{enumerate}. The code below demonstrates these ideas.

\documentclass[12pt]{article}
\newcounter{cenum}
\newcounter{cenumsaved}
\setcounter{cenumsaved}{0}
\newcommand{\labelcenum}{\arabic{cenum}.}
\newenvironment{cenumerate}%
{\begin{list}{\labelcenum}{\usecounter{cenum}}%
\setcounter{cenum}{\value{cenumsaved}}}%
{\setcounter{cenumsaved}{\value{cenum}}%
\end{list}}
\usepackage{outlines}
\begin{document}


\noindent \textit{This outline counts level one without stopping.}
\renewcommand{\outlinei}{cenumerate}
\begin{outline}
\1 One 
\1 Two  %\setcounter{outlinetemp}{\value{outlinei}}
\0 Some text
%\setcounter{\outlinei}{3}
\1 Three
\2 Sub-point to three
\1 Four
\end{outline}

\noindent \textit{This outline counts level two without stopping}
\renewcommand{\outlinei}{itemize}
\renewcommand{\outlineii}{cenumerate}
\setcounter{cenumsaved}{0}
\begin{outline}
\1 One 
\2 another point to one
\1 Two  %\setcounter{outlinetemp}{\value{outlinei}}
\2 another point to two
\0 Some text
%\setcounter{\outlinei}{3}
\1 Three
\2 Sub-point to three
\2 second sub-point to three
\1 Four
\end{outline}

\noindent \textit{Back to the default way}

\renewcommand{\outlinei}{enumerate}
\renewcommand{\outlineii}{enumerate}
\begin{outline}[enumerate]
\1 One
\1 Two 
\0 Some text
\1 Three 
\2 Sub-point to three
\1 Four
\end{outline}
\end{document}
  • This doesn't answer the question of having a list be resumed. As soon as you use a 0th layer \0, the list enumeration is restarted. How can you, for example, use a 0th layer and have the enumeration of the higher layer \1 be resumed after that? – Werner Feb 14 '20 at 23:20
  • Good point Werner. Thanks. I corrected the code with examples of how you could continue counting across level \1 or \2 despite an interruption from a higher level. – Notarobot2244 Feb 15 '20 at 06:58
1

With linguex this is just write \ex. text EnterEnter anywhere in the document, without enclosing it in any list environment:

\documentclass{article}    
\usepackage{linguex}    
\usepackage{lipsum} % for dummy text    
\begin{document}
\ex.  \lipsum[1][1-1]\par % end item always with a blank line (or \par) 
\ex.  \lipsum[2][1-3]\par 
\ex.  \lipsum[3][1-1]\par 
\lipsum[4][1-4]\par 
\ex.  \lipsum[5][1-3]\par 
\ex.  \lipsum[6][1-1]\par 
\lipsum[7][1-4]\par 
\section*{Foo}
\lipsum[8][1-4]\par 
\ex.  \lipsum[8][1-1]\par 
\ex.  \lipsum[9][1-1]\par 
\lipsum[10][1-1]\par 
\ex.  \lipsum[11][1-1]\par 
\ex.  \lipsum[12][1-1]\par 
\end{document}
Fran
  • 80,769