[Tex/LaTex] Length of \vfill

spacing

Is there a way to get the size of \vfill? I want to do some math with the spacing, and I already tried to do:

\newlength{\newtest}
\settowidth{\newtest}{\vfill}

I got an error.

Any sugestions?

Best Answer

\vfill is infinite glue. The amount is not a fixed value, but a "rubber length" that can span from 0pt to "infinity". Its real length is known, when TeX constructs its parental vertical box. Experts can inspect the box and determine the exact settings that TeX has chosen. However, there is also an easier way. Many TeX compilers support a feature that tells the position: pdfTeX (the inventor of the feature) in both modes PDF and DVI, XeTeX, LuaTeX). The position is known at the time, when the page is shipped out. Module savepos of package zref provides a wrapper that deals with the internals. It records the positions in the auxiliary file (.aux) as references and makes them available in the next LaTeX run.

\documentclass{article}
\usepackage{zref-savepos}
\usepackage{printlen}
\usepackage{lipsum}

\newcommand*{\posdiff}[2]{%
  \zifrefundefined{#1}{\textbf{??}}{%
    \zifrefundefined{#2}{\textbf{??}}{%
      \printlength{\dimexpr\zposy{#1}sp-\zposy{#2}sp\relax}%
    }%
  }%
}
\uselengthunit{mm}

\begin{document}
\section{Hello World}
\lipsum[1-2]

\hrule
\zsavepos{top}
\vfill
\zsavepos{bottom}
\hrule
\newpage
Vertical space on the previous page
between the lines: \posdiff{top}{bottom}
\end{document}

For the experts that want to debug TeX boxes:

  • \showbox expects a box handle and shows the box with its node contents in the .log file.
  • \showlists without parameters displays the current vertical main list.
  • \showboxbreadth and \showboxdepth are integer registers that control how much of the box contents is shown (boxes can be very huge). Their default values are -1 in LaTeX that suppresses the output.
  • The output is printed in the .log file only unless \tracingonline (also an integer register) is set to a positive value.