[Tex/LaTex] How to avoid underfull vbox in combination with \vsplit

boxesmacrostex-core

In the following example I am using the command \vsplit. I can't see the reason why \vsplit produced an overfull \vbox

\documentclass{article}
\parindent0pt
\def\exampletext{Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text }
\fboxsep=0pt
\fboxrule=1pt
\hfuzz=\maxdimen
\begin{document}
\setbox1=\vbox{
\hsize=8cm
\bfseries\huge\exampletext}
\boxmaxdepth0pt
\setbox0\vsplit1to2cm
\setbox0=\vbox{\unvbox0}
\fbox{\box0}

\fbox{\box1}
\end{document}

I used \hfuzz=\maxdimen to avoid overfull hbox in this example.

Best Answer

You get the Underfull \vbox message when TeX is doing the \vsplit: it wants to build a \vbox to 2cm, but it has to use a break point that doesn't produce a 2 cm high box. You correctly do \setbox0=\vbox{\unvbox0}, but the underfull box has already been produced.

\def\silencewarning{\edef\currentvbadness{\the\vbadness}%
  \vbadness=10000 \afterassignment\restorevbadness}
\def\restorevbadness{\vbadness=\currentvbadness\relax}

...
\silencewarning
\setbox0\vsplit1to2cm
...

This will tell TeX not to warn for the underfull box, but do the same computations as before. If your computations are performed in a group, then set \vbadness to 10000 (or \@M, which is the same) and forget about it.

Note. Box registers 1, 3, 5, 7 and 9 should be used only for global assignments. Not every package conforms to this recommendation, however.

Related Question