Create an exercise sheet or exam in LaTeX (exam)

The class exam numbers the questions inside a questions environment, takes the points as optional argument of \question, and prints or hides the solution environments with one option.

The snippets use the document class exam.

Questions with points

Each \question starts a numbered question; the value in square brackets is printed before the text as "(4 points)". A parts environment divides a question into (a), (b), (c) with \part. The class makes no heading, so the title of the sheet is ordinary text.

Complete document:

\documentclass[11pt, a4paper]{exam}

\begin{document}

\begin{center}
\textbf{\large Physics 1 -- Exercise Sheet 3}\\
Due on 19 May 2025
\end{center}

\begin{questions}
\question[4] State Newton's second law and name the quantities in it.

\question[6] A car accelerates from 0 to 100 km/h in 8 s.
\begin{parts}
\part[3] Calculate the mean acceleration.
\part[3] Calculate the distance covered.
\end{parts}
\end{questions}

\end{document}
Result
The compiled example

Open in the editor

Solutions in the same file

The content of solution is printed only with the class option answers or after \printanswers in the preamble. Without it, the optional length, here 3 cm, is left empty for the answer. One file therefore gives both the sheet and the solution sheet.

Complete document:

\documentclass[11pt, a4paper, answers]{exam}

\begin{document}

\begin{questions}
\question[2] How many seconds does one hour have?
\begin{solution}[3cm]
One hour has $60 \cdot 60 = 3600$ seconds.
\end{solution}
\end{questions}

\end{document}
Result
The compiled example

Open in the editor

Answer space and multiple choice

\vspace{3cm} leaves empty space after a question, and \fillwithlines{3cm} fills that height with lines to write on. choices lists answers as A, B, C, and checkboxes puts a box to tick before each. Mark the right answer with \CorrectChoice; it is highlighted only when the solutions are printed.

\begin{questions}
\question Explain why the sensor has to be calibrated.
\vspace{3cm}

\question Describe the test setup.
\fillwithlines{3cm}

\question Which unit does force have?
\begin{choices}
\choice Joule
\CorrectChoice Newton
\choice Watt
\end{choices}

\question Which of these is a vector?
\begin{checkboxes}
\choice Mass
\CorrectChoice Velocity
\end{checkboxes}
\end{questions}
Result
The compiled example

Open in the editor

Header, footer and grade table

\pagestyle{headandfoot} switches on header and footer; \header and \footer each take a left, a centre and a right part. \numpages is the number of pages. With the class option addpoints, \gradetable[h][questions] prints a table with the points of each question, their total and an empty row for the score; h sets it horizontally and v vertically. The totals are correct after three runs.

Complete document:

\documentclass[11pt, a4paper, addpoints]{exam}

\pagestyle{headandfoot}
\header{Physics 1}{Exam}{12 May 2025}
\footer{}{Page \thepage\ of \numpages}{}

\begin{document}

Name: \rule{6cm}{0.4pt}

\begin{center}
\gradetable[h][questions]
\end{center}

\begin{questions}
\question[4] State Newton's second law.
\question[6] Calculate the mean acceleration of a car that reaches 100 km/h in 8 s.
\end{questions}

\end{document}
Result
The compiled example

Open in the editor

German labels

babel does not translate the words of the class. \pointpoints sets the singular and plural of the points label, \solutiontitle holds the heading of a solution, and \hqword, \hpword, \hsword and \htword set the labels of the horizontal grade table. For the vertical table the commands are \vqword, \vpword, \vsword and \vtword.

Complete document:

\documentclass[11pt, a4paper, addpoints, answers]{exam}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\pointpoints{Punkt}{Punkte}
\renewcommand{\solutiontitle}{\noindent\textbf{Lösung:}\enspace}
\hqword{Aufgabe:}
\hpword{Punkte:}
\hsword{Erreicht:}
\htword{Summe}

\begin{document}

\begin{center}
\gradetable[h][questions]
\end{center}

\begin{questions}
\question[1] Wie viele Sekunden hat eine Stunde?
\begin{solution}
Eine Stunde hat 3600 Sekunden.
\end{solution}

\question[4] Nenne das zweite Newtonsche Gesetz.
\end{questions}

\end{document}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages