# How can I tie two pieces of text together so LaTeX tries not to break exactly between them?

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.)

-
put \nopagebreak between them. (It might needs some other changes as well, especially if you are using \flushbottom rather than \raggedbottom, but start there:-) –  David Carlisle Oct 18 '12 at 18:36
Maybe this one could help you. –  Benedikt Bauer Oct 18 '12 at 18:36
@DavidCarlisle: Oh, c'mon! That's too simple! ;-) –  Benedikt Bauer Oct 18 '12 at 18:37
This mostly depends on how you define the logical units for problem and solution. –  egreg Oct 18 '12 at 19:33

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.

-