# How to reduce as much as possible space taken by questions of an exam while avoiding questions that spill over multiple pages?

I have a set of rules for the questions of an exam I'm trying to design. I want to find a way to respect all the following rules:

_ if two or more questions can fit inside the same page, make it happen.

_ if one question spills over another page but that one or more questions may fit at the end of the last page of that first question,make it fit.

_ if one question doesn't fit normally on a single page, you don't have to make it fit on only one page, it's okay to have questions that are very long and spill over multiple pages.

Is there an environment that fits my criterias?

edit: one more rule:

_ if n questions fits inside a single page, but if you put the n+1th inside the same page and it spill over another page. Then make the n+1th be on the next page.

• Well, any breakable environment can do this, I think. Look for the 'breakable' features of mdframed or tcolorbox packages -- you will have to design the look of such 'question' boxes yourself, but that's pretty easy for both packages – user31729 Sep 1 '16 at 10:40
• @ChristianHupfer: I THINK that the OP's second rule is saying that the question order should change to optimize the spacing. For example, if Q2 won't fit at the bottom of page 1, then check to see if Q3 will fit there, etc. – James Sep 1 '16 at 11:19
• @James: Well, then let's remove the breakable thing and use the float feature -- my comment still holds ;-) – user31729 Sep 1 '16 at 11:28
• @ChristianHupfer: I've also wondered how to accomplish these rules in the past. I think your suggestion is to write each question inside a float and let LaTeX order the floats to achieve the best fit. Do you suggest a figure, table, or something else? Is it possible to satisfy the OP's third rule with floats? – James Sep 1 '16 at 11:37
• @James: At least tcolorbox supports the float option -- it will be a float type of its own – user31729 Sep 1 '16 at 11:46

Following the suggestions of @ChristianHupfer in his comments. I have used tcolorbox as follows to meet your rule numbers 1 and 3.

I think that, according to your rules, the following should be true.

• The red question should be on the top of page 1
• The green question should also be on page 1
• The blue question should be totally on page 2 (not starting at the bottom of page 1)

Can you verify?

\documentclass{article}
\usepackage{lipsum}
\usepackage[breakable]{tcolorbox}
\begin{document}
\pagestyle{empty}

\begin{tcolorbox}[breakable,colback=red!25!white] \lipsum[1] \end{tcolorbox}

\begin{tcolorbox}[breakable,colback=blue!25!white] \lipsum[2-5] \end{tcolorbox}

\begin{tcolorbox}[breakable,colback=green!25!white] \lipsum[6] \end{tcolorbox}

\end{document}


• Thank you for your answer. It indeed fits all the criteria I mentionned. But now I realize I forgot to mention another thing about it(another rule). I'll edit my post. – Simonlbc Sep 2 '16 at 10:54