[Tex/LaTex] How to tie two pieces of text together so LaTeX tries not to break exactly between them

page-breakingparagraphs

I'd like to typeset two chunks of text (a problem statement and solution) next to each other, but I don't want the problem to be the last thing on a page and the solution to be the first thing on the next page. Is there a way to get LaTeX to try to keep them together if they occur at a page boundary — for example, by pushing a few lines of the problem onto the solution page, or vice versa? (Each paragraph/section can be broken individually, but I would like the boundary to be on one page.)

Best Answer

There also is the samepage environment. I would try the following:

Random sentence of the problem. Random sentence of the problem. Random
sentence of the problem.

  \begin{samepage}
  One of the last sentences of the problem. The last sentences of the
  problem.

  The first sentence of the solution. Another sentence of the solution.
  \end{samepage}

Random sentence of the solution. Random sentence of the solution. Random
sentence of the solution.

Maybe that's good enough for you.

Related Question