4

I can resume by adding \setcounter{enumi}{\thetemp} before the first item \setcounter{temp}{\theenumi} after the last item where temp is my new counter. However this approach does not look elegant. I don't want to type those adjustments by hand. Is there any better way to inject those adjustments by patching?

\documentclass{article}
\usepackage{exsheets}
\usepackage{enumitem}

\begin{document}
\begin{question}
\begin{enumerate}[label=\arabic*.]
    \item one
    \item two
\end{enumerate}
\end{question}
\begin{solution}
\end{solution}

\begin{question}
\begin{enumerate}[resume,label=\arabic*.]
    \item must be three rather than one.
    \item must be four rather than two.
\end{enumerate}
\end{question}
\begin{solution}
\end{solution}
\end{document}

enter image description here

Display Name
  • 46,933
  • Probably due to the nested environments, see e.g. https://tex.stackexchange.com/questions/1669/resuming-a-list for a possible solution – albert Sep 16 '18 at 10:15

3 Answers3

6

You can use the series key:

\documentclass{article}
\usepackage{exsheets}
\usepackage{enumitem}

\begin{document}

\begin{question}
\begin{enumerate}[label=\arabic*., series=A]%
    \item one
    \item two
\end{enumerate}
\end{question}
\begin{solution}
\end{solution}

\begin{question}
\begin{enumerate}[resume*=A]
    \item must be three rather than one.
    \item must be four rather than two.
\end{enumerate}
\end{question}
\begin{solution}
\end{solution}

\end{document} 

enter image description here

Bernard
  • 271,350
  • +1. Given that the OP wants to automate things as much as possible, you may want to add the instruction \setlist[enumerate,1]{label=\arabic*.,resume=A} in the preamble, after loading the enumitem package. That way, the subsequent [label=\arabic*., series=A] and [resume*=A] option directives may be omitted. – Mico Sep 16 '18 at 10:35
  • 1
    @Mico: I already thought of this possibility, but what if only some questions have to share the same counter, another set of questions another counter, and so on? – Bernard Sep 16 '18 at 10:39
5

The enumitem package features a resume option, which you are attempting to employ. However, this option works only locally, i.e., not across other numbered environments. However, the package also features a method to make the resume feature apply globally; see section 3.5 of the package's user guide for the full details. The global form of resume differs from the local form of resume by making resume point to a "series". I suggest you create a dedicated enumerate-like environment (called, say, myenum) as follows:

\newlist{myenum}{enumerate}{1}
\setlist[myenum]{label=\arabic*.,resume=xyz}

That way, you still have access to the "regular" enumerate environment elsewhere in the document.

A full MWE (I'll skip the screenshot):

\documentclass{article}
\usepackage{exsheets}
\usepackage{enumitem}
\newlist{myenum}{enumerate}{1}
\setlist[myenum]{label=\arabic*.,resume=xyz}

\begin{document}
\begin{question}
\begin{myenum}
    \item one
    \item two
\end{myenum}
\end{question}
\begin{solution}
\end{solution}

\begin{question}
\begin{myenum}
    \item three
    \item four
\end{myenum}
\end{question}
\begin{solution}
\end{solution}
\end{document}
Mico
  • 506,678
5

If you want that the “subquestions” are numbered using the same series throughout the document, you can use the following:

\documentclass{article}
\usepackage{exsheets}

\newcounter{globalenumerate}
\newenvironment{genumerate}
 {\begin{enumerate}\setcounter{enumi}{\value{globalenumerate}}}
 {\setcounter{globalenumerate}{\value{enumi}}\end{enumerate}}

\begin{document}
\begin{question}
\begin{genumerate}
    \item one
    \item two
\end{genumerate}
\end{question}
\begin{solution}
\end{solution}

\begin{question}
\begin{genumerate}
    \item must be three rather than one.
    \item must be four rather than two.
\end{genumerate}
\end{question}
\begin{solution}
\end{solution}
\end{document}

This won't affect other usages of enumerate.

enter image description here

egreg
  • 1,121,712