2

Consider this example where a number from a previous reference is being used to set a counter.

\documentclass{article}

\begin{document}

\begin{enumerate}
\item \label{e:one} One
\end{enumerate}

\begin{enumerate}
  \setcounter{enumi}{\ref{e:one}}
  \item Next
\end{enumerate}

\end{document}

When LaTeX is run for the first time, we get an error about a missing number.

How do we avoid this error?

(My actual scenario of more complex than this where the messages are much more severe.)

EDIT

Looks like the actual scenario needs to be elaborated in order to save all from being misled.

\documentclass{exam}

\usepackage{lipsum}

\begin{document}

\begin{questions}

  \question [10]  \label{e:one} One

\end{questions}

\lipsum[1-5]


\begin{questions}

  \setcounter{question}{\ref{e:one}}
  \question [5] Next

\end{questions}

\end{document}
  • Why not use enumitem which has a resume option? – cfr Aug 21 '15 at 1:51
  • @cfr Because, as I said, my actual scenario is much more complex where enumitem can not be used. Actual counters are not enum or some such. – Masroor Aug 21 '15 at 1:54
  • In that case, it would help to know a bit more about the context because your current question doesn't make clear that, or why, enumitem isn't an option. There are many ways in which things could be more complex: I assumed that the label was being set in the way shown in the question. If it is not, how is it being set? – cfr Aug 21 '15 at 2:03
  • You could just use one questions environment and escape the indentation. That seems to be supported out-of-the-box. But I've never used this exam.cls (only the other exam.cls) so this is probably beyond my ken. – cfr Aug 21 '15 at 2:27
  • I am an avid user of exam.cls and have used that escape many times. But that does not work under the current scenario. – Masroor Aug 21 '15 at 2:47
4

Use \setcounterref from the refcount package:

\documentclass{exam}
\usepackage{lipsum}
\usepackage{refcount}

\begin{document}

\begin{questions}
\question [10]  \label{e:one} One
\end{questions}
\lipsum[1]


\begin{questions}
\question [5] Another
\question [5] Yet another
\setcounterref{question}{e:one}
\question [5] Next
\end{questions}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.