6

How do I keep questions from splitting between pages in exam? For example in the MWE below, I'd like to have a page break after Question 2 so that Question 3 can start on a new page. I don't particularly care how this is done but I imagine a vertical fill would work. Is there a command within exam that does this? I only see the commands that specify what to do with the header/footer if there is continuation but nothing about disabling continuation.

EDIT: Is there a way to make exam do this automatically instead of having me specify where to have a page break?

\documentclass[addpoints]{exam}
\usepackage{blindtext}

\begin{document}

\begin{questions}

\question
\blindtext[3]
\begin{choices}
\choice 
\choice 
\choice 
\choice 
\choice 
\end{choices}

%

\question
\blindtext
\begin{choices}
\choice 
\choice 
\choice 
\choice 
\choice 
\end{choices}

%

\question
\blindtext
\begin{choices}
\choice 
\choice 
\choice 
\choice 
\choice 
\end{choices}

%

\end{questions}
\end{document}
0

3 Answers 3

4

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
1
  • Thanks! This solves 90% of the problems. Btw, you have an errant \end{multichoice} in the code. Commented Oct 7, 2014 at 22:30
1

It looks to me that, if all else should fail, you can wrap your question-choice blocks in

\begin{minipage}{\linewidth}
\question \dots
\end{minipage}
1
  • 1
    If you do that, and use the \pointsinmargin feature, the points boxes overwrite the question numbers.
    – CPBL
    Commented Oct 6, 2014 at 20:30
0

I found this suggestion to do the trick but also being very compact/easy to integrate with existing code:

Yet another trick by Knuth is useful if you have a sequence of small blocks of text that need, individually, to be kept on their own page. Insert the command \filbreak before each small block, and the effect is achieved.

Source: LaTeX.org

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .