112

I want to do something like the following in TeX:

\begin{nobreak}  

Text here will not split over pages, it will remain
as one continuous chunk. If there isn't enough room
for it on the current page a pagebreak will happen
before it and the whole chunk will start on the next
page.  

\end{nobreak}

Is this possible?

lockstep
  • 250,273
fredley
  • 1,629

4 Answers4

87

See Preventing page breaks between lines in the TeX FAQ. Basically, you may use one of the following:

  • the samepage environment;
  • a \parbox or a minipage;
  • the \needspace command of the package of the same name.

You may also need "to accept that not everything can be accomplished totally automatically".

lockstep
  • 250,273
52

A \vbox (or \vtop) will never be broken across pages:

\vbox{%
  Text here will not split over pages, it will remain
  as one continuous chunk. If there isn't enough room
  for it on the current page a pagebreak will happen
  before it and the whole chunk will start on the next
  page.}

(unless you \setbox it, and later \unvbox it)

morbusg
  • 25,490
  • 4
  • 81
  • 162
13

You can also use packages to create and format the environment via options:

Marco Daniel
  • 95,681
2

\minipage works well when used in conjunction with the line width. To prevent overfull hbox's you need to use:

\noindent\begin{minipage}{\linewidth}
content on same page
\end{minipage}

The key is \linewidth. \linewidth is equivalent to the text width (\textwidth) when not in a list. When in a list, \linewidth accounts for the indentation of the list. One other item that may or may not be so obvious is you should have a blank line before the minipage block. If you don't the minipage block will become part of the text it's attached to and cause the overfull hbox. Example:

content 1

\noindent\begin{minipage}{\linewidth} content on same page \end{minipage}

content 2

In How make sure two elements stay on the same page? the suggestion was to use \textwidth but that doesn't work when in a list.