LaTeX forum ⇒ 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

Re: How do I keep exam choice options together on the same p

Postby 87234asdffdd » Sat Jul 11, 2015 7:09 pm

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.

  1. \question[\half]{What is the airspeed velocity of an unladen swallow?}
  2.  
  3. \nopagebreak\noindent\begin{minipage}[]{\linewidth}\begin{checkboxes}{}
  4.  
  5. \choice 10 m/s
  6.  
  7. \CorrectChoice What do you mean? African or European swallow?
  8.  
  9. \choice 8 m/s
  10.  
  11. \choice 12 m/s
  12.  
  13. \end{checkboxes}\end{minipage}{}

Tags:

fuhrmanator
Posts: 1
Joined: Tue Apr 10, 2018 11:22 pm

Postby fuhrmanator » Tue Apr 10, 2018 11:40 pm

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,

  1. \documentclass[answers, 10pt]{exam}
  2. \usepackage[margin=0.75in]{geometry}
  3. \usepackage{lipsum}
  4. \usepackage{indentfirst}
  5. \usepackage{enumerate}
  6.  
  7. \linespread{1}
  8.  
  9. \renewcommand{\rmdefault}{phv}
  10. \renewcommand{\sfdefault}{phv}
  11.  
  12.  
  13. \begin{document}\pagestyle{empty}\raggedright
  14.  
  15. \lipsum[1] \lipsum[1] \lipsum[1] \lipsum[1] \lipsum[1] \lipsum[2]
  16.  
  17.  
  18.  
  19. \begin{questions}
  20.  
  21. \filbreak
  22. \question Which of the following is an example of the correct answer?
  23.  
  24. \begin{choices}
  25. \CorrectChoice first answer
  26. \choice second answer
  27. \choice third answer
  28. \choice fourth answer
  29. \choice fifth answer
  30. \end{choices}
  31.  
  32.  
  33. \filbreak
  34. \question Which of the following is an example of the correct answer?
  35.  
  36. \begin{choices}
  37. \CorrectChoice first answer
  38. \choice second answer
  39. \choice third answer % This should be kept together with the first two choices
  40. \choice fourth answer
  41. \choice fifth answer
  42. \end{choices}
  43.  
  44.  
  45. \end{questions}
  46.  
  47. \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.


Return to “Document Classes”

Who is online

Users browsing this forum: No registered users and 2 guests