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.

I am creating an exam with two parts, the first part is short questions and the second part is essay question, and I would like to automatically count the number of questions for the two parts separately. By default, the \numquestions displays the total number of questions in the document.

\documentclass{exam}

\begin{document}

\begin{questions}
\fullwidth{\Large \textbf{Short questions}}    
There are \numquestions\ short questions. %display the number of short questions.

\question
This is the first short question.
\question
This is the second short question.

\setcounter{question}{0}

\fullwidth{\Large \textbf{Essay questions}}
There are \numquestions\ essay questions. %display the number of essay questions.

\question
This is the first essay question.
\question
This is the second essay question.
\question
This is the third essay question.
\question
This is the fourth essay question.
\end{questions}
\end{document}
share|improve this question
    
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. A suggestion: Do us a favour and change your username to something more telling than "jc2254". –  Martin Schröder Oct 21 '13 at 8:06

1 Answer 1

up vote 5 down vote accepted

Here is a solution using the totcount package and redefining the \question command with \squestion for the short questions and \equestion for the essay questions.

\documentclass{exam}

\usepackage{totcount}

\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}


\begin{document}

\fullwidth{\Large \textbf{Short questions}}    
There are \total{s}\ short questions. %display the number of short questions.

\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}

\setcounter{question}{0}

\fullwidth{\Large \textbf{Essay questions}}
There are \total{e}\ essay questions. %display the number of essay questions.

\begin{questions}
\equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}

For the record there is a total of \numquestions\ questions.

\end{document}

And here is the output:

Output

Note The \numquestions command hasn't been modified so that you can still use it if you need to have the total number of questions (both short ones and essay ones).

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.