[Tex/LaTex] How to ask LaTeX to exactly fill up a page

line-spacingsetspacespacing

I understand that I can control interline spacing in LaTeX in a number of ways. The commands like \baselineskip, \baselinestretch, \linespread come in handy in controlling the interline spacing. Each has its own speciality and circumstances of usage, as we can find in these discussions (A, B, C).

If want to go for a ready made solution for controlling line spacing, packages like setspace come in quite handy (built-in commands like \onehalfspacing or \setstretch for more finer controls).

Anyway, my problem is a bit different. I have some text (both in paragraph and list mode) which I want to fill up exactly one page. To complicate the scenario, it may even contain equations and graphics. (Let us leave aside floats.)

If I want to solve the problem statically, all I will have to is to play with some value of \baselineskip (or \setstretch) until satisfied. While this works good for most of the cases, I will have to go through the process again when I want to delete or add some texts.

Would it be possible to have a dynamic value for
\baselineskip or \setstretch so that my text always fills up one page? (Definitely within reasonable limits.)

Another idea will be to use a number of \vfills between some pieces of texts. But I think that this technique is usable for cover pages only.

I am not putting here an MWE. I think that one is not applicable.


The problem is not a theoretical one, I am preparing some kind of handout which I want to fill-up exactly one page.

Best Answer

You can add stretchability to \baselineskip:

\documentclass{article}
\usepackage[pass,showframe]{geometry} % just to show the page is filled up
\usepackage{kantlipsum}

\newcommand{\addstretch}[1]{\addtolength{#1}{\fill}}

\flushbottom

\begin{document}

\addstretch{\baselineskip}
\addstretch{\abovedisplayskip}
\addstretch{\abovedisplayshortskip}
\addstretch{\belowdisplayskip}
\addstretch{\belowdisplayshortskip}
\setlength{\parskip}{0pt}

\kant*[1]
\begin{equation}
E=mc^2
\end{equation}
\kant[2-3]

\newpage

\kant*[1]
\begin{equation}
E=mc^2
\end{equation}
\kant[2]

\newpage

\end{document}

Using \fill overrides the \vfil inserted by \newpage.

enter image description here

It's easy to make a onepage environment:

\newenvironment{onepage}
  {\newpage\flushbottom
   \addstretch{\baselineskip}
   \addstretch{\abovedisplayskip}
   \addstretch{\abovedisplayshortskip}
   \addstretch{\belowdisplayskip}
   \addstretch{\belowdisplayshortskip}
   \setlength{\parskip}{0pt}}
  {\newpage}

Here's the complete code with the environment:

\documentclass{article}
\usepackage[pass,showframe]{geometry} % just to show the page is filled up
\usepackage{kantlipsum}

\newcommand{\addstretch}[1]{\addtolength{#1}{\fill}}
\newenvironment{onepage}
  {\newpage\flushbottom
   \addstretch{\baselineskip}
   \addstretch{\abovedisplayskip}
   \addstretch{\abovedisplayshortskip}
   \addstretch{\belowdisplayskip}
   \addstretch{\belowdisplayshortskip}
   \setlength{\parskip}{0pt}}
  {\newpage}

\begin{document}

\begin{onepage}
\kant*[1]
\begin{equation}
E=mc^2
\end{equation}
\kant[2-3]
\end{onepage}

\begin{onepage}
\kant*[1]
\begin{equation}
E=mc^2
\end{equation}
\kant[2]
\end{onepage}

\end{document}