4

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}
4

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 – Alwin Jun 29 '16 at 2:28

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.