LaTeX tweak: Continuous enumeration over multiple sections

Soo…I move this from a former page to a post. At some point last year, I needed a solution for a problem in LaTeX, where I wanted to continue an enumeration over several paragraphs. Read on and find out how I did it. Cheers!

OK, I came across a problem, when trying to use something like the following:

\chapter{c1}
\section{s1}
\subsection{sub1}
Q1 - foo0
Q2 - bar0

\subsection{sub2}
Q3 - foo1
Q4 - bar1

\subsection{sub3}
Q5 - foo2
Q6 - bar2

So I tried. Hard. But could not get this to work. Finally, I used several counters to do the job. Not very nice but it works:

\chapter{c1}
% init new counters Rcount and Tcount
\newcounter{Rcount}
\newcounter{Tcount}

\subsection{subX}
%Tell the list to use counter Rcount, and use a custom label (RQ-arabicnumberOfCounter)
\begin{list}{Q-\arabic{Rcount}}{\usecounter{Rcount} \setlength{\rightmargin}{\leftmargin}}
%since the list environment sets the used counter to zero, we need to use the second counter and load it into Rcount.
  \setcounter{Rcount}{\value{Tcount}}
  \item fooX
  \item barX
\end{list}

%when the list is finished, write the value or Rcount back to the backup counter.
\addtocounter{Tcount}{\value{Rcount}}

That’s it. Hopefully it helps somebody. For any questions, just contact me.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.