[Tex/LaTex] Underfull hbox with \hbox to but not with \halign

boxeshorizontal alignmentwarnings

When using the \halign primitive, cells in the same column all have the same width. Hence, if one entry is very large (abcdefg below), the others will be stretched to the same size. If an entry contains no glue, then it is not stretched. Namely,

\halign{#\cr abcdefg\cr a b\cr ab\cr}

gives

abcdefg
a     b
ab

This can be emulated by applying \hbox to <wd>{...} to each entry. However, when there is no glue, \halign produces no Underfull hbox warning, whereas \hbox to <wd>{...} does.

  • Am I correct that \halign does the equivalent of \hbox to <dim>{...} to resize the entries?

  • I would like to avoid spurious Underfull hbox warnings. How can I test for the absence of glue in a \hbox?

Best Answer

You can test whether an \hbox is underfull without getting a message using something like

\begingroup
\setbox0=\hbox{...}
\hbadness=10000 % suppress `Underfull \hbox' messages
\setbox0=\hbox to <wd>{\unhbox0 }
\xdef\mybadness{\the\badness}
\endgroup

so \mybadness will expand to 10000 if the \hbox to <wd> is underfull. See the TeXbook, p. 229. By giving different values to <wd> you can also test if the glue is infinite or not.

Related Question