# Exam package labels multiply defined

I am using the exam package to create a questionnaire. I have two sections with multiple choice questions. When I put two "questions" environment under each sections, I get latex warning mentioning labels defined multiple times (Label question@1' multiply defined etc). Does anyone know how to avoid having two questions with same label? A sample code is given below

\documentclass[12pt]{exam}

\begin{document}

\section{On part one}

\begin{questions}

\question
Which of the following statements is/are True?
\begin{choices}
\choice B is true
\choice A is false
\correctchoice C is false
\end{choices}

\question
Why is this false
\begin{choices}
\correctchoice  Yay
\correctchoice  Bee
\correctchoice  See
\choice  Dee
\end{choices}

\end{questions}

\section{On part two}

\begin{questions}

\question
Which of the following statements is/are True?
\begin{choices}
\choice B is true
\choice A is false
\correctchoice C is false
\end{choices}

\question
Why is this false
\begin{choices}
\correctchoice  Yay
\correctchoice  Bee
\correctchoice  See
\choice  Dee
\end{choices}

\end{questions}

\end{document}


In order to do its business, the exam class uses self-defined labels, but in doing so it doesn't take into account the fact that question numbers are reset at every questions environment. Actually, the class seems to be expecting just one questions environment.

Using two will most certainly confuse the point system. If you don't plan to use it, you can do

\documentclass[12pt]{exam}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\questions}
{question@\arabic{question}}
{question@\arabic{section}@\arabic{question}}
{}{}
\makeatother
\begin{document}

\section{On part one}

\begin{questions}
\question
Which of the following statements is/are True?
\begin{choices}
\choice B is true
\choice A is false
\correctchoice C is false
\end{choices}

\question
Why is this false
\begin{choices}
\correctchoice  Yay
\correctchoice  Bee
\correctchoice  See
\choice  Dee
\end{choices}

\end{questions}

\section{On part two}

\begin{questions}
\question
Which of the following statements is/are True?
\begin{choices}
\choice B is true
\choice A is false
\correctchoice C is false
\end{choices}

\question
Why is this false
\begin{choices}
\correctchoice  Yay
\correctchoice  Bee
\correctchoice  See
\choice  Dee
\end{choices}

\end{questions}

\end{document}


The alternative is to use \section inside the single questions environment.

\documentclass[12pt]{exam}

\begin{document}

\begin{questions}
\section{On part one}
\question
Which of the following statements is/are True?
\begin{choices}
\choice B is true
\choice A is false
\correctchoice C is false
\end{choices}

\question
Why is this false
\begin{choices}
\correctchoice  Yay
\correctchoice  Bee
\correctchoice  See
\choice  Dee
\end{choices}

\section{On part two}

\question
Which of the following statements is/are True?
\begin{choices}
\choice B is true
\choice A is false
\correctchoice C is false
\end{choices}

\question
Why is this false
\begin{choices}
\correctchoice  Yay
\correctchoice  Bee
\correctchoice  See
\choice  Dee
\end{choices}

\end{questions}

\end{document}

• And also very quickly, use \fullwidth{\section{On part two}} if you want the section name to be aligned with the left margin Jun 29, 2016 at 2:28
• The first solution does suppress the warnings (thanks !) but, as stated, the point system is lost. examdoc.pdf section 9.1: "To use this feature ... there must be only one questions environment in the entire exam". For the second solution (section inside questions env), sections are indented (unless put in a \fullwidth{}`), and the question counter is not reset. Jul 1, 2021 at 20:03