# Conditional page breaking

I have used LaTeX on and off for a number of years now for several large documents with evolving versions over long lifetimes. But every time it seems like, powerful and wonderful as LaTeX is, there arise cases where I want to tweak the pagination in ways that are impossible without using the \newpage or \clearpage sledgehammer.

The macro I think I want is something like

\ifnotremaining{<length>}{<cmd>}

that is, if less than space remains on the page then perform . For example:

\ifnotremaining{5cm}{\newpage}

Note that <length> need not be perfect–if a little too big no problem, or a little small (perhaps because the "protected" text got bigger) then you just increase it a bit. FWIW, I am usually happy with \raggedbottom.

An alternative might be a \disablepagebreak and \enablepagebreak pair which could be used to forbid a page break in the given range of text. (This capability cannot be formulated as an environment because it cannot always nest wrt other environemnts.)

Is there something I have overlooked that can fill this need?

-
Welcome to TeX.sx! Maybe you want to have a look at the package needspace – egreg Feb 1 '13 at 14:29
Have you tried the pagebreak's optional argument? – vonbrand Feb 1 '13 at 14:30
the needspace package provides the \needspace{_space needed_} command (otherwise only available in memoir). the command looks pretty trivial, but it reserves the space you need. of course, this means you need to run your document to see where the page break falls, before adding the command. – wasteofspace Feb 1 '13 at 15:06
\needspace is new to me, but looks like exactly what I seek. I will definitely try it out. – Ron Brender Feb 1 '13 at 19:08

## 1 Answer

Let me switch the comments to an answer

The package needspace does exactly what are you looking for.

The package has the following introduction:

This packages two commands, \needspace and \Needspace, for reserving space to keep a certain amount of material from being split over a page break. If there is not enough space, a \newpage is automatically inserted.

-