Creating Professional Exams with LaTeX: A Complete Guide
Category: Latex
Date: 12 days ago
Views: 348
Introduction
If you're looking to create professional and structured exams using LaTeX, you're in the right place. Over the years, I’ve found the exam
document class to be an incredibly powerful tool for creating exams with questions, solutions, and even point-based grading. What I love most is the flexibility: you can include solutions for personal reference, but when you compile without the answers
parameter, they stay hidden—perfect for distributing to students. In this tutorial, I’ll guide you through some practical examples to help you get started.
Preamble and Exam Settings
The preamble in LaTeX is where you set up the structure and configurations for your document. For an exam, this includes defining the document class, setting up page geometry, and importing packages for additional functionality. In this case, we are using the exam
document class, which is specifically designed for creating exams with options for solutions, grading, and question formatting.
% Typeset exams with solutions in LaTeX
\documentclass[answers,addpoints,12pt,a4paper]{exam}
\usepackage[left=1.5cm,right=0.5cm,top=0cm,bottom=1cm]{geometry} % Set page margins
% \usepackage[french]{babel}
\usepackage{calligra} % For calligraphy font
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{tikz} % For drawing the vertical line
\usepackage{xcolor}
\pointname{}
\pointformat{\textbf{\textit{(\thepoints)}}}
% Exam settings
\pointsinmargin
% \colorfillwithlines
% \definecolor{FillWithLinesColor}{gray}{0.8}
\colorfillwithdottedlines
\definecolor{FillWithDottedLinesColor}{gray}{0.7}
\unframedsolutions
\renewcommand{\solutiontitle}{\noindent\textbf{}\enspace}
\SolutionEmphasis{\itshape\small}
\SolutionEmphasis{\color{red}}
The exam settings in the preamble customize the document's layout and functionality. For example, \pointsinmargin
places question point values in the margin for a cleaner look, while \colorfillwithdottedlines
fills answer spaces with dotted lines to guide students. Solution formatting is also fully customizable: \unframedsolutions
removes borders around solutions, and \SolutionEmphasis{\color{red}}
highlights them in red. These options allow you to tailor the exam to your preferences and needs.
Question Types
The exam
class provides various question types, making it highly versatile for creating exams. If compiled without the answers
parameter, you get a clean, professional exam. With the answers
parameter, the output includes solutions, perfect for creating a correction guide.
Check Options (Multiple Choice)
\question[2]
This question has one correct answer. Mark it.
\begin{checkboxes}
\choice The correct answer is after the second wrong answer.
\choice The correct answer is after this answer.
\choice This is the correct answer.
\CorrectChoice Previous answers are false.
\end{checkboxes}
\question[1]
Which of the following is not a Greek philosopher?\\
\begin{oneparcheckboxes}
\choice Socrates
\choice Plato
\choice Pythagoras
\CorrectChoice You
\end{oneparcheckboxes}
Fill in the Blank
\question[2] Fill in the blank using the following words:\\
\parbox{0.9\textwidth}{%
\colorbox{gray!30}{\parbox{\dimexpr\linewidth-2\fboxsep}{%
\centering
\textbf{\textit{Helium $-$ Sir Isaac Newton $-$ Alpha Centuri $-$ Einstein}}
}}
}\\[1ex]
\fillin[Helium] is the second element of the periodic table.\\
\fillin[Sir Isaac Newton][2in] discovered the first gravitational law.\\
The answer to \fillin[life, the universe and everything][3in] is 42
Direct Question with Space for Answers
\question[5]
In no more than one paragraph, explain why the earth is round.
\begin{solutionordottedlines}[1.5in]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris.
\end{solutionordottedlines}
These examples illustrate how to design and format exams with ease. By toggling the answers
parameter, you can switch between a student-ready exam and a solution-rich correction sheet.
The Exam
% Typeset exams with solutions in LaTeX
\documentclass[addpoints, 12pt, a4paper]{exam}
\usepackage[left=1.5cm,right=0.5cm,top=0cm,bottom=1cm]{geometry} % Set page margins
%\usepackage[french]{babel}
\usepackage{calligra} % For calligraphy font
\usepackage[T1]{fontenc}
\usepackage{amsmath, amssymb}
\usepackage{tikz} % For drawing the vertical line
\usepackage{xcolor}
\pointname{}
\pointformat{\textbf{\textit{(\thepoints)}}}
% Exam settings
\pointsinmargin
%\colorfillwithlines
%\definecolor{FillWithLinesColor}{gray}{0.8}
\colorfillwithdottedlines
\definecolor{FillWithDottedLinesColor}{gray}{0.7}
\unframedsolutions
\renewcommand{\solutiontitle}{\noindent\textbf{}\enspace}
\SolutionEmphasis{\itshape\small}
\SolutionEmphasis{\color{red}}
% Redefine the points display format in margin
\newcommand{\borders}{%
\tikz[remember picture, overlay, xshift=-0.5cm]{
\draw[gray, thick] (0,-1.2) -- (0,-27);
\draw[gray, thick] (0,-1.2) -- (\textwidth,-1.2);
\node[] at (0.5,-0.25) {\textbf{1\textsuperscript{er} bac S.E}};
\node[magenta] at (1.1,-0.6) {\textbf{www.mosaid.xyz}};
\node[xshift=-2cm] at (\textwidth,-0.25) {\textbf{\today}};
\node[xshift=-5.5cm] (A) at (\textwidth,-0.9) {\textbf{Name :}};
\node[xshift=-0.5cm] at (0.5\textwidth,-0.5) {\textbf{English Test n$^\circ$1 /2h}};
\draw[gray, thick] (A.south west) -- ++(0,0.7) -- ++(6.4,0) ;
\node[magenta] at (0.9\textwidth,-1.4) {\textbf{www.mosaid.xyz}};
}%
}
% Redefine \exo command to avoid spacing issues
\newcommand{\exo}[1]{%
\begin{tikzpicture}
% Node for the text
\node[] (text) at (0,0) {\textbf{#1}};
% Shadow (calculated based on the text width)
\fill[black] ([xshift=0.1cm, yshift=-0.1cm]text.south west)
rectangle ([xshift=0.1cm, yshift=-0.1cm]text.north east);
% Main box (calculated based on the text width)
\draw[fill=white] (text.south west) rectangle (text.north east);
% Text inside the box
\node[] at (text) {\textbf{#1}};
\end{tikzpicture}%
}
\footer{}{Page \thepage\ of \numpages}{}
\begin{document}
\borders\\[1cm]
\noindent\hspace*{0.1cm}
\exo{Whatever Subjects English teachers teach \hspace{2mm} (10pts)}
\begin{questions}
\question[2]
This question has one correct answer. Mark it.
\begin{checkboxes}
\choice The correct answer is after the second wrong answer.
\choice The correct answer is after this answer.
\choice This is the correct answer.
\CorrectChoice Previous answers are false.
\end{checkboxes}
\question[1]
Which of the following is not a Greek philosopher?\\
\begin{oneparcheckboxes}
\choice Socrates
\choice Plato
\choice Pythagoras
\CorrectChoice You
\end{oneparcheckboxes}
\question[2] Fill in the blank using the following words:\\
\parbox{0.9\textwidth}{%
\colorbox{gray!30}{\parbox{\dimexpr\linewidth-2\fboxsep}{%
\centering
\textbf{\textit{Helium ~$-$~ Sir Isaac Newton ~$-$~ Alpha Centuri ~$-$~ Einstein}}
}}
}\\[1ex]
\fillin[Helium] is the second element of the periodic table.\\
\fillin[Sir Isaac Newton][2in] discovered the first gravitational law.\\
The answer to \fillin[life, the universe and everything][3in] is 42\\
\noindent \hspace*{-0.6cm}
\exo{Language, writing and other english stuff \hspace{2mm} (10pts)}
\setcounter{question}{0}
\question[5]
In no more than one paragraph, explain why the earth is round.
%\fillwithlines{1.5in}
%\fillwithdottedlines
\begin{solutionordottedlines}[1.5in]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla
et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer
sapien est, iaculis in, pretium quis, viverra ac, nunc.
\end{solutionordottedlines}
\question
\begin{parts}
\part[2]
What changes to the van Allen radiation belt are needed to make
the earth into a regular icosahedron?
\begin{solutionordottedlines}[1in]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque.
\end{solutionordottedlines}
\part[3]
Where should the field generator be constructed if you want one of
the vertices to be located at the Royal Observatory at Greenwich?
\begin{solutionordottedlines}[1in]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo.
\end{solutionordottedlines}
\end{parts}
\end{questions}
%\begin{center}
%\hsword{text}
%\gradetable[h][questions]
%\end{center}
\begin{center}
{\scalebox{3}{\textbf{\textcolor{blue}{\calligra Good Luck!}}}}
\end{center}
\end{document}
And to have your solutions document, all you have to do is compile it using the parameter
in the documentclass like this:
\documentclass[answers,addpoints, 12pt, a4paper]{exam}
Conclusion
LaTeX is a powerful tool for creating professional exams, offering flexibility in formatting, question types, and solutions. With the exam
class, you can easily design multiple-choice, fill-in-the-blank, and direct-answer questions, all while maintaining a clean layout. By toggling the answers
parameter, you can switch between student-ready exams and detailed solution sheets for distribution after the test. Whether you're preparing an exam for your class or a correction guide, LaTeX provides the tools you need to create polished, customizable documents with ease.
0 Comments, latest
No comments.