## LaTeX forum ⇒ Document Classes ⇒ How 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.
LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am

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

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

2. And how do I change the spacing between adjacent choices?

I already went through the exam document class documentation and it did not answer my questions.


Tags:

Johannes_B
Site Moderator
Posts: 3963
Joined: Thu Nov 01, 2012 4:08 pm
It is right there behind the choices environment including an example.

The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am
Johannes_B, see my comments below:

1. How do I keep exam choice options together on the same page? (I did not ask how to condense all the options into one line; the actual exam will have short statements for response options and so I will need one choice per line.)

2. And how do I change the spacing between adjacent choices? (The space between A and B should be single spaced apart, and instead it is more than that, like, 1.5x the line spread.)

(Also ragged2e doesn't work a lot of the time for me, so that is why I use ragged right.)

cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm
LavaTyper wrote:1. How do I keep exam choice options together on the same page? (I did not ask how to condense all the options into one line; the actual exam will have short statements for response options and so I will need one choice per line.)

Interesting question. The usual idea would be to put it in a box since boxes never are broken at page boundaries. In LaTeX terms: put it in a {minipage}. This works but will separate the question from the choices:
\question Which of the following is an example of the correct answer? \noindent\begin{minipage}{\linewidth}\begin{choices}   \CorrectChoice first answer   \choice second answer   \choice third answer   \choice fourth answer   \choice fifth answer\end{choices}\end{minipage}

I can't say if that suffices for you.

For keeping the question and the possible answers together the logical idea would be to wrap the {minipage} around both
\noindent\begin{minipage}{\linewidth}\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}\end{minipage}

but for reasons I don't yet understand this destroys the formatting (the list is then too close to the question).

LavaTyper wrote:(Also ragged2e doesn't work a lot of the time for me, so that is why I use ragged right.)

That's strange... loading ragged2e shouldn't change anything unless you use an option like \usepackage[document]{ragged2e}. However, whatever your problems with the package are IMHO it might be worth trying to solve them and use the package, anyway...

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

Johannes_B
Site Moderator
Posts: 3963
Joined: Thu Nov 01, 2012 4:08 pm
Sorry, i missread the question. That happens.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am
So, the exam class has no built-in option to keep choices together and I have to use a minipage for each question? That seems rather disappointing.

LavaTyper wrote:2. And how do I change the spacing between adjacent choices? (The space between A and B should be single spaced apart, and instead it is more than that, like, 1.5x the line spread.)

Any idea?

Johannes_B
Site Moderator
Posts: 3963
Joined: Thu Nov 01, 2012 4:08 pm
You can define your own environment and use this instead. It will safe you some work.

To the second thing a little qick and dirty hack:
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

LavaTyper
Posts: 68
Joined: Sat Feb 11, 2012 2:38 am
That is not satisfying.

I have given up on the exam class and have gone back to using basic enumerate.

Johannes, you mentioned that using \raggedright "gets you into trouble" - well then how do I take care of the options in {enumerate}?

Also, how do I get the list items (choices) to have the same alignment even if one option continues onto a second line?


Johannes_B
Site Moderator
Posts: 3963
Joined: Thu Nov 01, 2012 4:08 pm
Package enumerate has its limitations. In the following code i used the more modern enumitem. The troubling raggedright was referring to the oneparchoices-environment. Both are incompatible with one another. There is no problem in the current example (at least i see none).

The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

StarValkyrie
Posts: 89
Joined: Fri Jan 24, 2014 12:42 am
I have my exam.cls-based exam template in LyX set up to prevent page breaks between choices. My solution only works in LyX though because LyX is set up already so that you can automatically append a custom command (which I can't take credit for - I googled for it) to all instances of a particular environment - in this case, both "choice" and "correctchoice".

In Preamble, I put:
\makeatletter  \newcommand\mynobreakpar{\par\nobreak\@afterheading}\makeatother

Then using the LyX Layout's RightDelim option, I have it add ~\mynobreakpar at the end of each choice line. That keeps the choices together. To prevent a page break between those answers and the question they belong to, I then have LyX append \pagebreak[3] after each \end{choices}.

This solution might or might not be reproducible without LyX by copying the relevant sections of code from the exam.cls that pertain to choices, choice and correctchoice environments and then inserting the commands - you'd have to play around with it and see.