0% found this document useful (0 votes)
19 views4 pages

Needspace

The needspace package provides two commands, \needspace and \Needspace, to reserve vertical space in LaTeX documents and prevent material from being split across page breaks. The \needspace command reserves an approximate length of space, while \Needspace reserves the exact length but is less efficient and should only be used between paragraphs. This package is maintained by the LaTeX Project team and is licensed under the LaTeX Project Public License.

Uploaded by

oaquinterol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Needspace

The needspace package provides two commands, \needspace and \Needspace, to reserve vertical space in LaTeX documents and prevent material from being split across page breaks. The \needspace command reserves an approximate length of space, while \Needspace reserves the exact length but is less efficient and should only be used between paragraphs. This package is maintained by the LaTeX Project team and is licensed under the LaTeX Project Public License.

Uploaded by

oaquinterol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

The needspace package

Author: Peter Wilson, Herries Press


Maintainer: LATEX Project team
https://github.com/LaTeX-Package-Repositories/herries-press

v1.3e 2025/03/13

1 Documentation
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.
The \needspace⟨length⟩ macro reserves an approximate amount of space
⟨length⟩ for the material following to be kept on the same page. The accuracy
of its calculations depend on what penalties are in effect, but is efficient and
normally adequate. A short page will be ragged bottom even if \flushbottom is
in effect.
\Needspace{⟨length⟩} is less efficient but reserves the requested space ⟨length⟩
exactly. It should only be used between paragraphs. Short pages that are pro-
duced by \Needspace will be ragged bottom but short pages produced by
\Needspace*{⟨length⟩} will be flush bottom if \flushbottom is in effect.

2 Examples
Here, we request that we need next five lines on a single page/column:

... previous text.

\needspace{5\baselineskip}
The next five lines ...

1
In this case, the space is reserved more accurately:

... previous text.

\Needspace*{4\baselineskip}
The major principles are:
\begin{itemize}
\item ...

Licence and copyright


This work may be modified and/or distributed under the terms and conditions of
the LATEX Project Public License1 , version 1.3c or later (your choice). The current
maintainer of this work is the LATEX Project team.

Copyright Peter Wilson, 1996–2003


Copyright Will Robertson, 2010, 2013
Copyright LaTeX Project, 2025

1 http://www.latex-project.org/lppl.txt

2
3 Implementation

%% See needspace.dtx for Copyright and other information

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{needspace}[2025/03/13 v1.3e reserve vertical space]

\newcommand{\needspace}[1]{%
\ifhmode \ifinner \@LRmoderr \else \par \fi \fi
\begingroup
\@tempskipb \lastskip
\vskip -\@tempskipb
\setlength\dimen@{#1}%
\advance\dimen@\@tempskipb
\vskip\z@\@plus\dimen@
\penalty -100
\vskip\z@\@plus -\dimen@
\vskip\dimen@
\penalty 9999%
\vskip -\dimen@
\vskip\@tempskipb % reinsert \lastskip
\endgroup
}

\newcommand\Needspace{%
\ifhmode \ifinner \@LRmoderr \else \par \fi \fi
\@tempskipb \lastskip
\vskip -\@tempskipb
\penalty-100
\begingroup
\@ifstar{\@sneedsp@}{\@needsp@}%
}

\newcommand\@sneedsp@[1]{%
\setlength\dimen@{#1}%
\advance\dimen@\@tempskipb
\dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
\ifdim \dimen@>\dimen@ii
\break
\else
\vskip\@tempskipb % reinsert \lastskip
\fi
\endgroup
}

3
\newcommand\@needsp@[1]{%
\setlength\dimen@{#1}%
\advance\dimen@\@tempskipb
\dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
\ifdim \dimen@>\dimen@ii
\ifdim \dimen@ii>\z@
\vfil
\fi
\break
\else
\vskip\@tempskipb % reinsert \lastskip
\fi
\endgroup
}

You might also like