In an exam I am writing, I have a short answer section and a multiple choice section. Each of these sections should have questions starting at 1. As pointed out in this question, if you want to do this and avoid warnings about name collisions of question labels you need to modify the question labels to include the section name; I have done this using \xpatchcmd
as shown in the example below. The patch is successful (verified by looking at the .aux file and lack of warning messages).
The problem is that I do not want the grade table organized by page or grade number, but rather by section. Since there does not appear to be a built in way to create a grade table in this way, I am doing it manually by using \begingraderange
, \endgraderange
, and \pointsinrange
in a custom table. The issue that I am having is that the \pointsinrange
totals are not accurate. I think it is because there is still some sort of name collision beyond the question labels that happens when summing the points in the ranges; I think it has to do with the \newlabel
commands in the .aux files (marked with <===
below), where the unique question labels are defined but the value for each of these are the same.
When I run the following code, in the grade table I get that both the Short Answer and Multiple Choice have 2 total points, but it should be 10 and 4, respectively. I get the correct value for the overall total points (14). Any thoughts on how I can get this to work properly while also being able to reset the question number in each section to 1?
\documentclass[11pt,addpoints]{exam}
% The following patches avoid name collisions with questions
% of the same number in different sections by adding the section
% name to the question label.
\usepackage{xpatch}
\xpatchcmd{\questions}{question@\arabic{question}}
{question@\arabic{section}@\arabic{question}}{}{}
\xpatchcmd{\parts}{part@\arabic{question}@\arabic{partno}}
{part@\arabic{section}@\arabic{question}@\arabic{partno}}{}{}
\xpatchcmd{\first@questionobject}{question\arabic{question}}
{question\arabic{section}@\arabic{question}}{}{}
\xpatchcmd{\addquestionobject}{question\arabic{question}}
{question\arabic{section}@\arabic{question}}{}{}
\xpatchcmd{\questionobject@pluspagecheck}{question\arabic{question}}
{question\arabic{section}@\arabic{question}}{}{}
\begin{document}
\section{Short Answer}
\begin{questions}
\begingradingrange{section1}
\question[5] First Question
\question[5] Second Question
\endgradingrange{section1}
\end{questions}
\section{Multiple Choice}
\begin{questions}
\begingradingrange{section2}
\question[2] First Question
\question[2] Second Question
\endgradingrange{section2}
\end{questions}
\section{Extra Credit}
\begin{questions}
\bonusquestion[5] Bonus
\end{questions}
\begin{center}
\begin{tabular}{|r|c|c|}
\hline
\multicolumn{3}{|c|}{\textbf{Exam Score}} \\ \hline
\textbf{Section} & \textbf{Points} & \textbf{Score} \\ \hline
Short Answer & \pointsinrange{section1} & \\ \hline
Multiple Choice & \pointsinrange{section2} & \\ \hline
Bonus & \numbonuspoints & \\ \hline
Total & \numpoints & \\ \hline
\end{tabular}
\end{center}
\end{document}
Excerpt of the .aux file:
...
\PgInfo{question@1@2}{1}
\PgInfo{question1@2@object1}{1}
\newlabel{question@1@2}{{2}{1}} <=== Value same as question@2@2
...
\PgInfo{question@2@2}{1}
\PgInfo{question2@2@object1}{1}
\newlabel{question@2@2}{{2}{1}} <=== Value same as question@1@2
TeX
arithmetic.\long\def\g@prepend@macro#1#2{% \begingroup \toks@\expandafter{#2#1}% \xdef#1{\the\toks@}% \endgroup}
Then use this to store the current amount of points in some macro. Then \AtEndDocument you can say\foreach \i in {0,...,\thesection}{\advance \thex by \numbercorrespondingtosection}
or something. Would probably be one (general) way to do it. (Untested though, but it may provide a framework to get done what you want.)