Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  John Wickerson May 11 '13 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. –  Peter Jansson May 11 '13 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 –  Misha Rogalla May 11 '13 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) –  David Carlisle May 11 '13 at 12:36

2 Answers 2

up vote 5 down vote accepted

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}
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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