Exam class: make \fillin draw box instead of line

exam

I am using the exam document class to create worksheets with fill-in-the-blank questions. By default, the \fillin command generates underlined empty space where students can write their answer. Is it possible to modify this behavior so that \fillin creates a box instead? Ideally I would be able to specify the height and the linewidth of the box. I would like to keep the ability to specify the correct solution to the \fillin command.

Minimal working example:

\documentclass{exam}
\begin{document}

\begin{questions}
\question How many grams are in one kilogram?

\vspace{1in}
1 kg = \fillin[1000] g.
\end{questions}

\end{document}

generates

enter image description here

but I would like to get something like

enter image description here

Best Answer

Without modifying the class:

\documentclass{exam}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@fillin@relay}
  {\hbox to #1{\hrulefill}\fi}
  {\hbox{\framebox[#1]{\rule{0pt}{2ex}}}\fi}
  {}{}
\makeatother

\begin{document}

\begin{questions}
\question How many grams are in one kilogram?

1 kg = \fillin[1000] g.
\end{questions}

\end{document}

enter image description here

Related Question