# What happens when \textheight changes mid-document?

I know it's generally considered to be unwise, but I need to understand what happens when \textheight changes mid-document. From this example, it appears that the change takes effect on the next page, when \vsize is changed.

\documentclass{article}
\begin{document}
\typeout{Page 1:}
\showthe\textheight
\showthe\vsize
abc
\newpage
\typeout{Page 2:}
\showthe\textheight
\showthe\vsize
def
\newpage
\typeout{Page 3:}
\showthe\textheight
\showthe\vsize
ghi
\end{document}


Is this always the case?

It is not "unwise" to change \textheight in mid-document - it is unsupported and by changing it midway strange things can happen. On the whole you are right, if you do this then it appears to affect the next page, but there are dependencies to the float algorithm which are asynchronous to the pages (for example, a float is tested when encountered to ensure that it doesn't exceed \textheight, and if so it will get artificially shortened so that the float algorithm can expect that all floats fit onto the page).

But there are also other surprising side-effects: try out this example:

\documentclass[twocolumn]{article}

\usepackage{lipsum}

\begin{document}

%\begin{figure*}  X\\Y \end{figure*}  %  <--- uncomment for test and watch what happens to page 2

1\\2\\3\\4\\5\\6\\7\\8\\9 \newpage

\lipsum

\end{document}


Here is what you get with and without the float on page 2 (the height reduction happens only from page 3 onwards):

But with the float already the second page gets shortened but has too much material now:

Now this is something one could argue is a LaTeX 2e (or even LaTeX2.09) bug, but then one could call it a feature as it is unsupported input.

In summary, if you need to understand what's really going on because you want to build something that changes \textheight then I fear you need to study all the places where it is being used

grep textheight latex.ltx
grep @colht latex.ltx


and whether what happens there can effect what you are trying to do --- but as I said it is not a supported interface variable.

• Thanks for the detailed answer. I don't want to build something that changes \textheight mid-document, but the exam document class does so if \extraheadheight is used with an optional argument that changes the header size on the first page. I considered trying to debug its behaviour, but now I have decided to avoid this feature instead. – Ian Thompson Mar 22 '12 at 15:51
• @Ian don't know what the exam class does here and right now can't check, but for something like the first page using \enlargethispage might be safer. – Frank Mittelbach Mar 22 '12 at 15:56

\textheight is also consulted at various points in the float placement algorithm. This is why the lscape package (which changes \textheight of course) does a \clearpage when switching size. If a float floats from the point at which it decided it needed to float, to a point where \textheight is different, the effects must be deterministic, but they are probably all bad....

It's probably worth noting that for temporary changes to the page height the \enlargethispage command is the supported interface, and it's not exactly a coincidence that this is essentially implemented using a hidden internal float, and doesn't change \textheight.

\textheight does take effect only after the current page ends.

if you really need to change the height of the current page, \enlargethispage is what you want. however, i have no idea what would happen if you intend the page to be occupied by a full-length float, or even if you want to allow a just slightly-too-large "regular" float to coexist on the current page with some text. (david can probably address that if you insist.)

it's probably worth mentioning that the effect of enlargethispage vanishes after the current page is output. it's not intended to persist for the remainder of the document.

• well, most of what is affected happens only after the current page ends. But unfortunately it isn't a clean situation as I explained and showed in my answer. – Frank Mittelbach Mar 22 '12 at 15:58
• thanks, @Frank, you can be counted on to keep me honest. – barbara beeton Mar 22 '12 at 16:02