I have generated the following document using exam class.
I would like to add the marks for each of Questions 2, 3 and 4 and write the total either next to underneath the Section II heading.
I know how to get the total marks for all questions, just not a total for questions within a particular section.
1 Answer
Well, you cannot count the marks per section directly, only per page. So I used a counter and add the question points to that counter. Three things: you cannot use half points, you have to update the counter after each question and you have to reset the counter before typesetting the next section.
\documentclass[a4paper,addpoints]{exam}
\renewcommand{\thepartno}{\alph{partno}}
\renewcommand{\partlabel}{(\thepartno)}
\marksnotpoints
\pointsinrightmargin
\newcounter{sectionpoints}\setcounter{sectionpoints}{0}
%% This will remove the points being typeset after the question number and part letter.
%% Use \droppointsatend to typeset points at the end of the current line.
%% If \droppointsatend is called at the question level, the points will
%% be prepended with a \dotfill, otherwise the points will be prepended
%% with a \hfill.
\makeatletter
\@qformatfalse
\def\droppointsatend{%
\def\level@of@question{question}%
\leavevmode\unskip\nobreak%
\ifx\level@of@question\@queslevel%
\dotfill(\mbox{\totalpoints\ \points})%
\else%
\hfill\mbox{[\@points]}%
\fi%
\par
%% Make sure we drop the points at the right
\pointsdroppedatright
}
%% Get the total points from the current question as an integer
\def\valuepointsofquestion{\@ifundefined{pointsofq@\romannumeral \arabic{question}}%
{0}%
{\csname pointsofq@\romannumeral \arabic{question}\endcsname}%
}%
\makeatother
\begin{document}
\begin{questions}
\uplevel{\textbf{Section I}}
\question Some text \droppointsatend
This question is worth \totalpoints\ \points
\begin{parts}
\part[5] Some text \droppointsatend
\part[5] Some text \droppoints % \droppointsatend
\part[5] Some text \droppoints % \droppointsatend
\part[5] Some text \droppoints % \droppointsatend
\end{parts}
\addtocounter{sectionpoints}{\valuepointsofquestion}
\question[10] Compute $\displaystyle \int_0^1 \!x^2\,\mathrm{d}x $ \droppointsatend
This question is worth \totalpoints\ \points
\addtocounter{sectionpoints}{\valuepointsofquestion}
\uplevel{The total \points\ for this section is \thesectionpoints.}
\uplevel{\textbf{Section II}}
\setcounter{sectionpoints}{0}
\question[15] Compute $\displaystyle \int_0^\infty\!\mathrm{e}^{-x^2}\,\mathrm{d}x$ \droppointsatend
\addtocounter{sectionpoints}{\valuepointsofquestion}
\question Some text \droppointsatend
\addtocounter{sectionpoints}{\valuepointsofquestion}
\begin{parts}
\part[5] Some text \droppoints % \droppointsatend
\part[5] Some text \droppoints % \droppointsatend
\part[5] Some text \droppoints % \droppointsatend
\part[5] Some text \droppoints % \droppointsatend
\end{parts}
\uplevel{The total \points\ for this section is \thesectionpoints.}
\end{questions}
\bigskip
\noindent Total to earn: \numpoints\ \points
\end{document}
-
As an additional query, is there a way to now add the totals from both sections? Aug 29, 2018 at 22:37
-
1
-
I cannot get this updated version to run. The following error is thrown up: missing number, treated as zero. \addtocounter{sectionpoints}{\totalpoints}. I am running LyX on Windows10. Aug 31, 2018 at 21:59
-
Hmmm that’s strange. What version of exam.cls are you using? Sep 1, 2018 at 6:57
-