6

I'd like to prevent page breaks between a question and its answer choices in the Exam class. There's a good solution to the problem of how to prevent page breaks within the answer choices here, but that question did not address how to prevent breaks between the question and the answers.

2
  • The easy solution is to put a single minipage around both the question and the choices. It isn't automatic, but it isn't exactly onerous either. – John Kormylo Jan 23 '15 at 22:09
  • I managed to implement the solution sugested by @Kormylo. The following code, adapts the right margin to the available width of questions or parts: ``` \begin{minipage}{\linewidth} aquí las preguntas o partes \end{minipage} ``` – djnavas Mar 24 '16 at 5:23
5

Add these lines

\usepackage{etoolbox}
\BeforeBeginEnvironment{checkboxes}{\par\nopagebreak\minipage{\linewidth}}
\AfterEndEnvironment{checkboxes}{\endminipage}

to the preamble to make question and checkboxes to go together..

\documentclass[answers]{exam}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\usepackage{etoolbox}
\usepackage{etoolbox}
\BeforeBeginEnvironment{checkboxes}{\par\nopagebreak\minipage{\linewidth}}
\AfterEndEnvironment{checkboxes}{\endminipage}

\CorrectChoiceEmphasis{}
\textheight3.4in   %% just for demo
\begin{document}
\begin{questions}
\question Random text for question 1
\begin{checkboxes}
\choice answer 1
\choice answer 2
\choice answer 3
\choice answer 4
\choice answer 5
\CorrectChoice answer 6
\end{checkboxes}

\question Random text for question 2
\begin{checkboxes}
\choice answer 1
\choice answer 2
\choice answer 3
\CorrectChoice answer 4
\choice answer 5
\choice answer 6
\end{checkboxes}

\question Random text for question 3
\begin{checkboxes}
\choice answer 1
\choice answer 2
\choice answer 3
\choice answer 4
\choice answer 5
\CorrectChoice answer 6
\end{checkboxes}

\question Random text for question 4
\begin{checkboxes}
\choice answer 1
\choice answer 2
\choice answer 3
\choice answer 4
\choice answer 5
\CorrectChoice answer 6
\end{checkboxes}

\question Random text for question 5
\begin{checkboxes}
\choice answer 1
\choice answer 2
\choice answer 3
\choice answer 4
\choice answer 5
\CorrectChoice answer 6
\end{checkboxes}

\end{questions}

\end{document}
1
  • This works for the checkboxes environment. However, \question is not an environment. Is there a solution for avoiding page breaks between the question and - for example - \solutionorlines? – Black Jul 9 '19 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.