How do I keep questions from splitting between pages in exam?
The answer How to prevent page breaks in lists? ("Exam" class) by @Mico is only for protecting the choices in a multiple-choice list, not the entire question. It still allows page breaks between a question prompt and its list of options. To avoid that, just define a new environment (shown here for multiple choice):
\documentclass[%answers,
addpoints,12pt]{exam}
\boxedpoints
% \pointsinmargin % Not compatible with the minipaging of multichoice questions
\newenvironment{mcquestion}[3]{ \begin{minipage}{\linewidth} \question[#1][#2] #3 \begin{choices}}{ \end{choices} \end{minipage}}
\begin{document}
\gradetable[h]
\begin{questions}
\begin{mcquestion}{1}{2 min}{Foodle:}
\choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \end{mcquestion}
\begin{mcquestion}{1}{2 min}{Foodle:}
\choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \end{mcquestion}
\begin{mcquestion}{1}{2 min}{Foodle:}
\choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \choice fish A \end{mcquestion}
\end{questions}
\end{document}
This now protects the whole question from breaking.
Note: one problem with the above is that if I want to use the \pointsinmargin
option, they overwrite the question number.
But I'm unable to apply @Mico's code to an environment (multichoice
) in the way he does. Using the following (and multichoice
environment instead of mcquestion
) does not compile:
\newenvironment{multichoice}[3]{
\question[#1][#2]#3
\begin{choices}}{ \end{choices}
}
\usepackage{etoolbox}
\AtBeginEnvironment{multichoice}{%
\par\medskip\begin{minipage}{\linewidth}}
\makeatletter
\AtEndEnvironment{multichoice}{%
\if@correctchoice \endgroup \fi%
\end{minipage}}
\makeatother