Getting Started with the Exam Class
Creating professional-looking exams, quizzes, and worksheets can be a formatting nightmare in standard word processors. Questions shift when you add an image, numbering breaks, and keeping a separate answer key often leads to version-control errors.
LaTeX solves these problems using the exam document class. This specialized environment automates question numbering, point calculations, and even the generation of grading tables and answer keys.
While you can create worksheets using the standard article class and list environments, the exam class is the gold standard for educators. It provides built-in commands specifically designed for academic assessment.
To begin, you must define your document class at the very top of your .tex file:
\documentclass[12pt, addpoints]{exam}
\begin{document}
% Content goes here
\end{document}The addpoints option is particularly useful—it tells LaTeX to keep track of all the points you assign to questions so it can calculate the total automatically.
Creating Questions and Sub-parts
In the exam class, all questions must be contained within the questions environment. Instead of using \item, you use the \question command.
Basic Question Structure
Each question can be assigned a point value by placing the number in square brackets immediately after the command.
\begin{questions}
\question[5] What is the chemical symbol for Gold?
\question[10] Explain the process of photosynthesis in three sentences or less.
\end{questions}Breaking Questions into Parts
Often, a single question has multiple components. The exam class allows for nesting using parts, subparts, and subsubparts.
\begin{questions}
\question[10] This question relates to basic calculus.
\begin{parts}
\part Define a "limit" in your own words.
\part Solve for $x$: $\lim_{x \to 2} (3x + 5)$.
\begin{subparts}
\subpart Is this function continuous?
\subpart Why or why not?
\end{subparts}
\end{parts}
\end{questions}Note: LaTeX handles the indentation and labeling (e.g., a, b, c then i, ii, iii) automatically, ensuring your document looks consistent throughout.
Multiple Choice and Selection Questions
The exam class offers several ways to format multiple-choice questions. The most common are the choices and oneparchoices environments.
choices: Lists options vertically.oneparchoices: Lists options horizontally in a single paragraph (great for saving paper).checkboxes: Replaces letters (A, B, C) with empty boxes.
Example: Multiple Choice Styles
\question[2] Who developed the Theory of General Relativity?
\begin{choices}
\choice Isaac Newton
\choice Galileo Galilei
\choice Albert Einstein
\choice Nikola Tesla
\end{choices}
\question[2] Which of these is a prime number?
\begin{oneparchoices}
\choice 4
\choice 9
\choice 11
\choice 15
\end{oneparchoices}Creating Answer Keys and Solutions
One of the most powerful features of LaTeX for teachers is the ability to keep the questions and the answers in the same file. You can toggle the visibility of the answers with a single command.
Defining Solutions
Use the solution environment for open-ended questions and the \CorrectChoice command for multiple-choice questions.
% Add this to your preamble to show answers
% \printanswers
\question[5] What is $2 + 2$?
\begin{solution}
The answer is 4. This is basic arithmetic.
\end{solution}
\question[2] Which color is a primary color?
\begin{choices}
\choice Green
\CorrectChoice Blue
\choice Orange
\end{choices}How to use it:
- To print the student version: Keep
\printanswerscommented out (add a%before it) or remove it. - To print the teacher version: Include
\printanswersin your preamble.
When \printanswers is active, the \CorrectChoice items will be bolded (or marked with a check) and the solution blocks will appear with a boxed border.
Tip: You can change the appearance of the solution box using
\unframedsolutionsif you prefer the answers to appear as plain text without a frame.
Designing the Header and Grade Table
A professional exam needs a header for the student's name and a way to track the score.
Custom Headers
The exam class provides \firstpageheader and \runningheader (for subsequent pages). They take three arguments: left, center, and right.
\pagestyle{headandfoot}
\firstpageheader{Math 101}{Midterm Exam}{October 24, 2023}
\runningheader{Math 101}{Midterm}{Page \thepage}
\firstpagefooter{}{}{}Automatic Grade Tables
Because we used the addpoints option in the document class, LaTeX can generate a grading table automatically. This table will update itself whenever you change the point values of your questions.
\begin{center}
\gradetable[h][questions] % [h] for horizontal, [v] for vertical
\end{center}
\begin{questions}
% Your questions here...
\end{questions}Best Practices and Common Pitfalls
To make your worksheets and exams as effective as possible, keep these tips in mind:
- Use
\fillinfor blanks: Instead of typing underscores, use\fillin[Answer][2cm]. This creates a standard-length line and can automatically print the answer when\printanswersis active. - Space for answers: Use
\vspace{2in}or\vfillafter a question to give students enough room to write. If you use\vfill, the space will expand to fill the available page. - Clear page breaks: Use
\newpageto ensure a question and its parts aren't split awkwardly across two pages. - Don't forget the environment: A common beginner mistake is placing a
\questionoutside of the\begin{questions}and\end{questions}tags. This will result in a compilation error. - Point totals: If your grade table shows "0" or "??", ensure you have included the
addpointsoption in your\documentclassand that you have actually assigned points like\question[10].
By using the exam class, you shift your focus from "fiddling with margins" to "designing quality content." Once you have a template you like, creating your next worksheet is as simple as swapping out the text of the questions.
