6

Using the exam document class I'm trying to create a questions/answers-sheet for a book. When working on the first chapter, everything worked nicely. When I came to the second chapter, I realized I would have problems with the question numbering, since there are questions with the same numbers. The specific warnings I got was:

LaTeX Warning: Label `question@1' multiply defined.

The basic layout of the body of my document is as follows:

\section*{Chapter 1}
\setcounter{section}{1}
    \begin{questions}
        \numberwithin{question}{section}
        \setcounter{question}{0}
        \question

            \begin{solution}

            \end{solution}
    \end{questions}

\section*{Chapter 2}
\setcounter{section}{2}
    \begin{questions}
        \numberwithin{question}{section}
        \setcounter{question}{0}
        \question

            \begin{solution}

            \end{solution}
    \end{questions}

Compilation still works, but my editor is giving me a page full of warnings. There has to be a better more correct way, than what I'm doing right now. Could you recommend me a different way to make such a document?

4
  • Welcome to the site, Martin. Please could you provide a complete .tex file (starting with \documentclass etc) so that I can reproduce your error on my machine? May 11, 2013 at 12:08
  • Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. May 11, 2013 at 12:17
  • @JohnWickerson I can't upload the full document. I have made a similar document, which produces the same warning: gist.github.com/MartinRogalla/5559828
    – Martin
    May 11, 2013 at 12:26
  • @MartinRogalla we don't need a full document we just need the example in the question fixing (you only need to add three more lines) May 11, 2013 at 12:36

3 Answers 3

5

Looking at the source exam class would need quite a few changes to use repeated numbers as it uses the number counter internally in several places. However to help anyone else answering and to address other problems in the posted document here is a start at a solution.

You shouldn't use star form for numbered sections, and \numberwith should only be used once. the fact that it wasn't having an effect and you had to manually reset the question counter is related to your use of the * form. Nested counters reset when the parent counter is incremented with \stepcounter (or better \refstepcounter) setting the section counter via \setcounter does not do this (and also means you can not use \label and \ref to refer to the section.

update Perhaps the easiest way to restart the equation numbering without breaking the rest of the features is to maintain the counter with unique numbers eg 101, 1002, in the first section and 201, 202 in the second, and then just arrange that this gets printed as 1.1,1.2,2.1,2.1 in the heading:

enter image description here

\documentclass{exam}
\usepackage{amsmath}

\makeatletter

\def\@seccntformat#1{%
  \expandafter\ifx\csname the#1\endcsname\thesection Chapter~\fi
  \csname the#1\endcsname
  \setcounter{question}{\thesection00}%
   \quad}

\renewcommand\thequestion{%
\the\numexpr(\value{question}-49)/100\relax.%
\the\numexpr\value{question}-(100*((\value{question}-49)/100))\relax}

\makeatother

\begin{document}

    \begin{questions}
\fullwidth{\section{}}
        \question aaa

            \begin{solution}
xxx
            \end{solution}


\fullwidth{\section{}}

        \question bbb

            \begin{solution}
yyy
            \end{solution}
    \end{questions}

\end{document}
0

I know this is an old question, but I had a similar problem and the answer here didn't solved it for me.

What I did was changing two lines in the exam.cls file, I didn't work with chapters, but for this case you can do this:

line2566

\edef\@queslabel{question@\arabic{question}}%

to

\edef\@queslabel{question@\arabic{chapter}@\arabic{section}@\arabic{subsection}@\arabic{question}}%

and

line2893

\edef\@partlabel{part@\arabic{question}@\arabic{partno}}%

to

\edef\@partlabel{part@\arabic{chapter}@\arabic{section}@\arabic{subsection}@\arabic{question}@\arabic{partno}}%

I only changed this two since they were the ones giving me the warnings and I don't use subparts or subsubparts. I guess if needed, those should be changed too.

0
  1. Changing the

\LoadClass{article}

to

\LoadClass{book}

  1. Follow piptin, modify

    2.1

\edef\@queslabel{question@\arabic{question}}%

to

\edef\@queslabel{question@\arabic{chapter}@\arabic{section}@\arabic{subsection}@\arabic{question}}%

2.2

\edef\@partlabel{part@\arabic{question}@\arabic{partno}}%

to

\edef\@partlabel{part@\arabic{chapter}@\arabic{section}@\arabic{subsection}@\arabic{question}@\arabic{partno}}%

then it works!!!!!!!!!!!!!!!!!!!!!!!!!!!

2
  • Please open a new question and give the link to this question. Otherwise you won't get an answer since this area is reserved for answers of this specific question.
    – percusse
    May 22, 2015 at 19:16
  • StackExchange isn't a message board; this is the space for answers, not discussion about answers. Another question with a link to this one is what you really need, or add a comment to the answer you're inquiring about, asking for clarification. May 22, 2015 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .