Document ClassesHow do I keep exam choice options together on the same page?

Information and discussion about specific document classes and how to create your own document classes.
87234asdffdd
Posts: 7
Joined: Mon Jul 06, 2015 4:46 pm

How do I keep exam choice options together on the same page?

Post by 87234asdffdd »

cgnieder wrote:For keeping the question and the possible answers together the logical idea would be to wrap the {minipage} around both
I did something different that seems to work. There are two problems, and here are the solutions:
  • The question can be separated from the answers by a page break. SOLUTION: a \nopagebreak before the {minipage} as below.
  • Multi-line questions can be broken up across pages. SOLUTION: define "widow penalties", assuming questions aren't more than 2 lines long. SOLUTION: wrap the question with a {minipage}. Either way, keeping an entire paragraph on the same page is a tricky thing to pull off in LaTeX, as discussed at http://www.tex.ac.uk/FAQ-nopagebrk.html.

Code: Select all

\question[\half]{What is the airspeed velocity of an unladen swallow?}

\nopagebreak\noindent\begin{minipage}[]{\linewidth}\begin{checkboxes}{}

\choice 10 m/s

\CorrectChoice What do you mean? African or European swallow?

\choice 8 m/s

\choice 12 m/s

\end{checkboxes}\end{minipage}{}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
fuhrmanator
Posts: 1
Joined: Tue Apr 10, 2018 11:22 pm

How do I keep exam choice options together on the same page?

Post by fuhrmanator »

LavaTyper wrote:1. How do I keep exam choice options together on the same page?
I'm late to this party, but finally found an old-school (from Knuth himself!) solution that suited me in my context: http://www.tex.ac.uk/FAQ-nopagebrk.html
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.
In my cases, I put a \filbreak before each \question,

Code: Select all

\documentclass[answers, 10pt]{exam}
\usepackage[margin=0.75in]{geometry}
\usepackage{lipsum}
\usepackage{indentfirst}
\usepackage{enumerate}
 
\linespread{1}
 
\renewcommand{\rmdefault}{phv}
\renewcommand{\sfdefault}{phv}
 
 
\begin{document}\pagestyle{empty}\raggedright
 
\lipsum[1] \lipsum[1] \lipsum[1] \lipsum[1] \lipsum[1] \lipsum[2] 
 
 
 
\begin{questions}
 
\filbreak
\question Which of the following is an example of the correct answer?
 
\begin{choices}
\CorrectChoice first answer
\choice second answer
\choice third answer
\choice fourth answer
\choice fifth answer
\end{choices}
 

\filbreak 
\question Which of the following is an example of the correct answer?
 
\begin{choices}
\CorrectChoice first answer
\choice second answer
\choice third answer % This should be kept together with the first two choices
\choice fourth answer
\choice fifth answer
\end{choices}
 
 
\end{questions}
 
\end{document}


but you could probably put it before the answers if you're OK with a break happening between the question and the answers.
Post Reply