About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.


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:

\half

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:

\addpoints

(to switch it on) and

\noaddpoints

(to switch it off).

The answers class option will display solutions. Again there are commands to switch this mode on and off:

\printanswers

(to show the solutions) and

\noprintanswers

(to hide the solutions).

All the exam questions should be contained within the single questions environment.

\begin{questions}
exam questions
\end{questions}

Within the questions environment, you start a new question using:

\question[points]

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

\titledquestion{title}[points]

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:

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.

Name and section: ____________________

Instructor's name: ____________________

  1. (3½ points) What ingredients can be found in mind-controlling cookies?
  2. (2½ points) What are the health benefits of exploding chocolates?
End of Image.


Questions may have parts, sub-parts or sub-sub-parts. Question parts should be enclosed in the parts environment:

\begin{parts}
question parts
\end{parts}

where each part is started with

\part[points]

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:

\begin{subparts}
question sub-parts
\end{subparts}

where each sub-part is started with

\subpart[points]

Sub-sub-parts should be enclosed in the subsubparts environment:

\begin{subsubparts}
question sub-sub-parts
\end{subsubparts}

where each sub-sub-part is started with

\subsubpart[points]

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:

  1. Find the derivatives with respect to 𝑥 of the following functions:
    1. (½ point) 𝑦 = 𝑥 + 1
    2. (1 point) 𝑦 = 𝑥³ + 4𝑥² − 𝑥 + 3
    3. (1½ point) 𝑦 = cos(𝑥²)
End of Image.


If you want to specify questions worth bonus points you can use

\bonusquestion

instead of \question,

\bonustitledquestion

instead of \titledquestion,

\bonuspart

instead of \part,

\bonussubpart

instead of \subpart and

\bonussubsubpart

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

\pointsinmargin

which puts the points in the left margin, or the declaration

\pointsinrightmargin

which puts the points in the right margin. If you prefer to place the points elsewhere, use the declaration

\pointsdroppedatright

to switch off the automatic placement of the points and use

\droppoints

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:

\numquestions

(the number of questions),

\numparts

(the number of parts),

\numsubparts

(the number of sub-parts), and

\numsubsubparts

(the number of sub-sub-parts).

If you have used the addpoints option, you can reference the total number of points using:

\numpoints

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:

\gradetable[orientation][index type]

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.

\begin{coverpages}
text
\end{coverpages}

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.

\begin{solution}[length]
solution text
\end{solution}

If the solutions are hidden, this environment inserts ⟨length⟩ amount of blank space (as though you had used \vspace*{length}).

\begin{solutionorbox}[length]
solution text
\end{solutionorbox}

The solutionorbox environment is similar to the solution environment, but inserts an empty box of height ⟨length⟩ if the answers should be hidden.

\begin{solutionorlines}[length]
solution text
\end{solutionorlines}

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.

\begin{solutionordottedlines}[length]
solution text
\end{solutionordottedlines}

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:

\choice

to start a new choice. To indicate the correct choice, use

\CorrectChoice

instead of \choice.

\begin{choices}
list items
\end{choices}

The choices environment is a list environment with labelled choices as the items in the list.

\begin{oneparchoices}
list items
\end{oneparchoices}

The oneparchoices is an in-line list of labelled choices where there are no paragraph breaks unless explicitly inserted.

\begin{checkboxes}
list items
\end{checkboxes}

The checkboxes environment is a list environment with checkbox choices as the items in the list.

\begin{oneparcheckboxes}
list items
\end{oneparcheckboxes}

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:

  1. (1 point) Which of the following ingredients are used in mind-controlling cookies:
    1. arsenic
    2. cyanide
    3. curare
    4. secret genetically modified sugar beet
End of Image.


For more details about the exam class, including commands and options not mentioned here, see the exam class user guide [36].

Exercise 24. Creating an Exam Paper with the exam Class

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).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs