[Tex/LaTex] Why doesn’t \settoheight of \parbox work

boxescalculationslengths

Consider the following code:

\documentclass[a4paper]{letter}
\usepackage{calc}
\usepackage{printlen}

\newsavebox{\foobox}
\newlength{\fooboxheight}

\savebox{\foobox}{
    \parbox[t]{\textwidth}{Line 1\\Line 2\\Line 3\\Line 4}
}
\settoheight{\fooboxheight}{\usebox{\foobox}}

\begin{document}

\usebox{\foobox}


Address box height: \printlength{\fooboxheight} \uselengthunit{mm} \printlength{\fooboxheight}

\end{document}

\fooboxheight is 7pt / 2mm, much smaller than the height of the \parbox! Why is this? What should I do to get the real height of the \parbox?

Interestingly, if the \parbox is surrounded by a \frame, everything works.

Best Answer

Insert the lines

\showthe\ht\foobox
\showthe\dp\foobox

and all will be clear: The height of \foobox is indeed 6.83331pt just as you have found. The depth, on the other hand, is 36pt. Notice that boxes have height and depth both, as measured from the baseline of the box. In this case, this happens because you use \parbox[t]. If you switch to \parbox[b] things might work more like you expect, at least as far as the height calculation goes. But then, of course, the baseline of the box may not be where you need it to be.

Related Question