# Generating gradetables with parts using the exam class

I've just started using the exam class to typeset, well, an exam, and when using the \gradetable command to create the final grade table, it only shows me the points at the granularity of a question, but not the parts (or subparts, etc.) of that question, as the following example illustrates:

\documentclass[addpoints]{exam}

\begin{document}

\begin{questions}
\question
What if there were no air?
\begin{parts}
\part[4]
Describe the effect on the balloon industry.
\part[6]
Describe the effect on the aircraft industry.
\end{parts}
\question
\begin{parts}
\part[12]
Define the universe.
Give three examples.
\part[8]
If the universe were to end, how would you know?
\end{parts}
\end{questions}

\end{document}


Is there anyway to make the gradetable split up the points into parts, or should I do it myself?

Sorry, but there's no way to have the gradetable list individual parts. You can list the points either by question number or by page number, but those are the only options.

• Is there any plan on adding this functionality? Many times we prefer explicitly marking how many points they got in each part. – fabikw Nov 2 '16 at 19:46
• This functionality would be useful indeed ... – Jairo Bochi May 10 '19 at 14:58
• I second that.... – Asking Questions Oct 16 '19 at 12:56

Whilst it is true that the exam class does not provide this functionality it is rarely true that it is not possible to do something in LaTeX. The question is more how hard it is to do what you want and in this instance it is not very difficult.

One way to add marks for the \part's to the grade table is to redefine the \part command so that it extracts the points for each part. This is slightly tricky to do as the \part command is actually (re)defined by the parts environment. Once you figure out what to do, however, you can construct the grade table on the fly using the marks for each part so that the MWE above produces:

Note that I have fallen prey to my own preferences and used booktabs to create the new grade table, which is produced by the \GradeTable command. The code below may break some other features of the exam package. For example, I noticed from exam.cls that "bonus marks" are supported in some fashion but I do not know what they are, how they work, or if my code is compatible with them. As far as I can see, however, my code should not break anything. On the other hand, the \GradeTable command does not support the full functionality of the \gradetable command. For example, it is not possible list marks by page numbers etc.

\documentclass[addpoints]{exam}

\usepackage{xparse,booktabs,xpatch}

% redefine \part command to be \mypart
\appto\parts{\let\exampart\part\let\part\mypart}

\makeatletter
\ExplSyntaxOn

\int_new:N \g_score_int% this will be the exam score
\NewDocumentCommand\mypart{o}{
\IfNoValueTF{#1}{\exampart}{
% don't do anything special inside solutions
\if@insolution\exampart[#1]
\else\exampart[#1]
\int_compare:nNnT {\arabic{partno}} = {1} {
}
\arabic{question}\alph{partno}
}
\tl_gput_right:No \g_grade_table_tl  {& #1 & \\}
\fi
}
}
\begin{tabular}{ccc}\toprule Question & Points & Score \\
Total & \int_use:N \g_score_int & \\\bottomrule
\end{tabular}
}
\ExplSyntaxOff
\makeatother

\begin{document}

\begin{questions}
\question
What if there were no air?
\begin{parts}
\part[4]
Describe the effect on the balloon industry.
\part[6]
Describe the effect on the aircraft industry.
\end{parts}
\question
\begin{parts}
\part[12]
Define the universe.
Give three examples.
\part[8]
If the universe were to end, how would you know?
\end{parts}
\end{questions}


• As far as I can tell, this is not a suitable option if you mix points for questions and parts. It also does not provide the option to put the table at the beginning of the exam. It is still nice though to see someone making an effort to achieve this. – Asking Questions Oct 16 '19 at 12:58