17

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

7
  • put \nopagebreak between them. (It might needs some other changes as well, especially if you are using \flushbottom rather than \raggedbottom, but start there:-) Commented Oct 18, 2012 at 18:36
  • 1
    Maybe this one could help you. Commented Oct 18, 2012 at 18:36
  • @DavidCarlisle: Oh, c'mon! That's too simple! ;-) Commented Oct 18, 2012 at 18:37
  • Please add a minimal working example (MWE) that illustrates your problem. It would be easier to help you that way.
    – Werner
    Commented Oct 18, 2012 at 18:53
  • This mostly depends on how you define the logical units for problem and solution.
    – egreg
    Commented Oct 18, 2012 at 19:33

3 Answers 3

14

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.

7

I personally like \filbreak because it goes back to Knuth (and it nests better than some of the other approaches). See the FAQ:

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 the following, if page breaks happen, they will tend to happen at the \filbreaks.

\filbreak
Here is the problem statement that goes on and on and on. And even more.

Here is the solution statement that goes on and on. And even more

\filbreak
Here is the problem statement that goes on and on and on. And even more.

Here is the solution statement that goes on and on. And even more

\filbreak
Here is the problem statement that goes on and on and on. And even more.

Here is the solution statement that goes on and on. And even more
1

My solution was to keep both pieces of text in a minipage environment.

I first had:


They were the first Hamkens on the Hamkenshof. In the distance we see more
upright sandstones, to the right and left of the door to a mausoleum. Here
lie the Gonnens, including the parents of Mrs. Ponke. North of the church we
find the gravestone of

\bigskip

\centerline{Councilor \personname{Peter Hamkens} (B 16)}

I wanted to keep the text explanation on the same page as the inscription "Councilor Peter Hamkens" on the gravestone, but these were often separated.

Neither \nopagebreak nor the samepage environment worked for me.

I simply put both the text and the inscription in a minipage, which is treated as a single line by LaTeX:

\noindent
\begin{minipage}{1\textwidth}
    They were the first Hamkens on the Hamkenshof. In the distance we see more
upright sandstones, to the right and left of the door to a mausoleum. Here
lie the Gonnens, including the parents of Mrs. Ponke. North of the church we
find the gravestone of

\bigskip

\centerline{Councilor \personname{Peter Hamkens} (B 16)}
\end{minipage}

It worked great and didn't require using any new packages.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .