9.1 ⁑The exam Class
The exam class is a comprehensive class for typesetting
examination papers. The user guide [36] is over
100 pages, so this section is only intended as a brief introduction.
The exam class has the standard class options, such as
10pt
, 11pt
and 12pt
, but also
provides two other options addpoints
and answers
,
described below.
The addpoints
class option enables the
point-totalling commands. If this option is used, all points must be
specified as integers. Half points may be indicated with the
command:
For example, 2\half
instead of 2.5.
In addition to the addpoints
class option, you can also
switch this mode on and off using the commands:
(to switch it on) and
(to switch it off).
The answers
class option will display
solutions. Again there are commands to switch this mode on and off:
(to show the solutions) and
(to hide the solutions).
All the exam questions should be contained within the single
questions
environment.
Within the questions
environment, you start a new
question using:
where ⟨points⟩ is the number of points this question is worth.
As mentioned above, if the addpoints
option is on,
⟨points⟩ must an integer with optionally the \half
command
(or just the \half
command on its own). The question is
automatically numbered.
You can replace \question
[
⟨points⟩]
with
if question should have a title. (The question number won't be
included by default, but you can add it to the title using
\thequestion
in the ⟨title⟩ argument.)
The exam class user guide [36] suggests the following code if you want to provide space for the student to fill in their name if they are to write on the question sheet:
\begin{center} \fbox{\parbox{5.5in}{\centering Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back of the page.% }} \end{center} \vspace{0.1in} \makebox[\textwidth]{Name and section:\enspace\hrulefill} \vspace{0.2in} \makebox[\textwidth]{Instructor's name:\enspace\hrulefill}
(Although you may prefer to use a fraction of \textwidth
instead of the hardcoded 5.5in.)
Example:
\documentclass[addpoints]{exam} \begin{document} \begin{center} \fbox{\parbox{0.8\textwidth}{\centering Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back of the page.% }} \end{center} \vspace{0.1in} \noindent\makebox[\textwidth]{Name and section:\enspace\hrulefill} \vspace{0.2in} \noindent\makebox[\textwidth]{Instructor's name:\enspace\hrulefill} \begin{questions} \question[3\half] What ingredients can be found in mind-controlling cookies? \question[2\half] What are the health benefits of exploding chocolates? \end{questions} \end{document}
This produces:
Questions may have parts, sub-parts or sub-sub-parts. Question parts
should be enclosed in the parts
environment:
where each part is started with
Note that outside of the parts
environment this command
behaves as the standard \part
sectioning command.
Sub-parts should be enclosed in the subparts
environment:
where each sub-part is started with
Sub-sub-parts should be enclosed in the subsubparts
environment:
where each sub-sub-part is started with
As with \question
, the optional argument indicates the number
of points the part is worth, and should only contain digits or
\half
if the addpoints
option is on.
Example:
\begin{questions} \question Find the derivatives with respect to $x$ of the following functions: \begin{parts} \part[\half] $y = x + 1$ \part[1] $y = x^3 + 4x^2 - x + 3$ \part[1\half] $y = \cos(x^2)$ \end{parts} \end{questions}
The result is:
If you want to specify questions worth bonus points you can use
instead of \question
,
instead of \titledquestion
,
instead of \part
,
instead of \subpart
and
instead of \subsubpart
.
The default location of the points is after the question (or part) number. This can be changed to the margin using the declaration
which puts the points in the left margin, or the declaration
which puts the points in the right margin. If you prefer to place the points elsewhere, use the declaration
to switch off the automatic placement of the points and use
at the end of the paragraph where you want the points displayed. If you use
\pointsdroppedatright
but don't use \droppoints
the
points won't be displayed. Note that \droppoints
should only
occur at the end of a paragraph or between paragraphs.
The number of questions, parts, sub-parts and sub-sub-parts can be referenced with the commands:
(the number of questions),
(the number of parts),
(the number of sub-parts), and
(the number of sub-sub-parts).
If you have used the addpoints
option, you can
reference the total number of points using:
For example:
This exam has \numquestions\␣questions worth a total of \numpoints\␣points.
With the addpoints
option, you can also display a grading table
using:
where ⟨orientation⟩ may be either h (horizontal) or v (vertical) and ⟨index type⟩ may be either questions or pages. The defaults are a vertical table indexed by question. The grading table provides space for the student marks to be written in by hand. You will need at least two LaTeX runs (possibly three or four) to ensure the grading table is up-to-date.
If you want to centre the grading table, you can place it in the
center
environment, which will add extra vertical space at the
start and end as well as centre its contents. (It's unlikely that you'll want
the grading table in a floating environment as it typically appears
in a fixed location.) The grading table is placed in a tabular
environment, so it can't break across a page.
Any cover page material can be place in the coverpages
environment.
The cover pages use Roman numeral page numbers. The page counter is
reset at the end of the environment. This environment must not
contain the questions
environment.
There are four environments for typesetting the solutions. The
default behaviour is for the solutions to be hidden. To display the
solutions, use the answers
class option. Each
environment takes an optional argument, which is the amount of space
to be left for the students to write in their solution. If the
optional argument is omitted, all four environments simply ignore
their contents when the answers
option hasn't been set.
If the solutions are hidden, this environment inserts ⟨length⟩
amount of blank space (as though you had used
\vspace
*{
⟨length⟩}
).
The solutionorbox
environment is similar to the
solution
environment, but inserts an empty box of height
⟨length⟩ if the answers should be hidden.
The solutionorlines
environment is similar to the
solution
environment, but inserts an area of height
⟨length⟩ with ruled lines if the answers should be hidden.
The solutionordottedlines
environment is similar to
solutionorlines
but uses dotted lines.
Example:
\begin{questions} \question Find the derivatives with respect to $x$ of the following functions: \begin{parts} \part[\half] $y = x + 1$ \begin{solution} $y' = 1$ \end{solution} \part[1] $y = x^3 + 4x^2 - x + 3$ \begin{solution} $y' = 3x^2 + 8x - 1$ \end{solution} \part[1\half] $y = \cos(x^2)$ \begin{solution} $y' = -2x\sin(x^)$ \end{solution} \end{parts} \end{questions}
There are four environments provided for multiple choice questions. The first two label the choices and the other two print checkboxes in front of the choices for the student to tick. With these environments use:
to start a new choice. To indicate the correct choice, use
instead of \choice
.
The choices
environment is a list environment with
labelled choices as the items in the list.
The oneparchoices
is an in-line list of labelled choices
where there are no paragraph breaks unless explicitly inserted.
The checkboxes
environment is a list environment with
checkbox choices as the items in the list.
The oneparcheckboxes
is an in-line list of checkbox
choices where there are no paragraph breaks unless explicitly inserted.
Example:
\begin{questions} \question[1] Which of the following ingredients are used in mind-controlling cookies: \begin{choices} \choice arsenic \choice cyanide \choice curare \CorrectChoice secret genetically modified sugar beet \end{choices} \end{questions}
This produces:
For more details about the exam class, including commands and options not mentioned here, see the exam class user guide [36].
Create an examination paper containing the questions (and solutions) in
the above examples and add a grading table. Try experimenting with
adding and removing the answers
class option and try the
variations of the solution
environment (such as
solutionorbox
).
The exam class user guide [36] describes ways of adjusting the default
settings. Try adding the command \unframedsolutions
to the preamble and
see how it changes the way the solutions are displayed or add
\bracketedpoints
to see how it affects the way the points are displayed.
You can download
or
view
a solution.
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).