I'm using the exam
documentclass and I would like to keep the spacing between questions the same whether or not the solutions are printed using \printanswers
(so it has the effect if the solutions being "written on" the original exam). I've seen these similar questions on this site, but the answers they provide either directly relate to tikz
(which I'm not using), or feel contrived and seem to circumvent the correct usage of the solution
environment:
Exam class: same space solution vs. no solution
(user Thomas F. Sturm is correct that this question isn't a duplicate)Preserve vertical spacing between paragraphs in different pages
The exam
class documentation (under section 8.3.3 Advanced customizations) seems to suggest that the only way to maintain the spacing is to edit the TheSolution
environment in the exam.cls
file (search for \newenvironment{TheSolution}
), but this is a bit beyond my abilities. Is there an easy way to maintain the spacing that I am missing? Or is there a simple way to edit the TheSolution
environment to make this happen?
Obligatory MWE. The \stretch{1}
spacing is eliminated when \printanswers
is uncommented.
\documentclass[12pt]{exam}
\usepackage[margin=1in]{geometry}
\unframedsolutions
\renewcommand{\solutiontitle}{}
% \printanswers
\begin{document}
\begin{questions}
\question
Ask some question here.
\begin{solution}[\stretch{1}]
The answer is 42.
\end{solution}
\question
Ask some other question
\begin{solution}[\stretch{1}]
I'm way up on the page if there are solutions.
\end{solution}
\end{questions}
\end{document}
\ifprintanswers\vspace{\stretch{1}}\fi
after each\end{solution}
will work, but there should still be a cleaner solution that this.etoolbox
to automate yours:\AtEndEnvironment{solution}{\ifprintanswers...\fi}
.