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?

4 Answers 4

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

4
  • 2
    Fair enough. I would have thought this was a desirable thing to have, especially for bullet lists etc. Oh well, thanks for your help.
    – fredley
    Oct 23, 2010 at 22:00
  • @lockstep what controls the spacing prior to samepage environment, I am getting more vertical whitespace, is this normal? Jun 7, 2013 at 5:58
  • 2
    Is there something equivalent to samepage but prevents column breaks in a two-column doc? (I want some chunk to stay in a single column). Sep 4, 2015 at 12:56
  • \nopagebreak worked for me.™ May 31, 2016 at 2:55
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)

13

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

2
  • 4
    Using my adjustbox package here would be overkill. A normal minipage usually does it. Of course if you want to add frames or other modifications it is the way to go. Oct 6, 2011 at 19:53
  • @MartinScharrer: Of course it's only useful for modifactions. Oct 7, 2011 at 9:45
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.

You must log in to answer this question.

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