Error Caused by The \makebox Command When Used Inside an Exam Document Header

compilation errorerrorsexamheader-footer

I am using the exam package for the first time. I wanted to edit the header as mentioned on page 117 of the documentation. The \makebox command is causing an error of the type: Missing \begin{document}... This happens when the optional arguments of size and position are used, i.e., \makebox[size][position]{text}, but when used without them, it raises no errors, however, the text in \makebox{text} would be misplaced. Any suggestions?

Here is a minimum non-working example (taken from the documentation linked above):

\documentclass[addpoints, 12pt]{exam}

\pagestyle{headandfoot}
\lhead{\large\bfseries Foundations of Mathematics (MATH113)\\ Midterm Exam, December 21, 2021}
\chead{}
% This is the line causing the problem!
% specifically: the optional arguments of \makebox[][]{}
\rhead[\large\bfseries Name:\enspace\makebox[2in]{\hrulefill}]{}
\lfoot{}
\cfoot[]{Page \thepage}
\rfoot{}
\begin{document}

\begin{center}
    \fbox{\fbox{\centering Minimum Working Example}}
\end{center}

\end{document}

Best Answer

The solution to this problem was provided by David Carlisle in the comments section. It involves wrapping the \makebox[size][position]{text} command by extra curly brackets to hide the optional arguments of size and position so that the \makebox command won't raise the error it does as shown in the question.

\documentclass[addpoints, 12pt]{exam}

\pagestyle{headandfoot}
\lhead{\large\bfseries Foundations of Mathematics (MATH113)\\ Midterm Exam, December 21, 2021}
\chead{}
\rhead[\large\bfseries Name:\enspace{\makebox[2in]{\hrulefill}}]{}
\lfoot{}
\cfoot[]{Page \thepage}
\rfoot{}
\begin{document}

\begin{center}
    \fbox{\fbox{\centering Minimum Working Example}}
\end{center}

\end{document}

Exam document header after fixing \makebox

Related Question