- I save a box containing a
\parbox
. - I set height of other
\parbox
es to the height of my saved box using TeX\the\ht\box
Code
For some reason, not all boxes are of the same size.
\documentclass{article}
\usepackage{fontspec}
\setlength\fboxsep{0pt}% perfectly size box around content
\setlength\fboxrule{.1pt}
\begin{document}
% Our goal is to specify the height dynamically as a function of the width and content of the box, which we set explicitly here:
\newsavebox{\tmpparbox}
\savebox{\tmpparbox}{\fbox{\parbox{40mm}{This parbox is top aligned with top-aligned content. And more text to fill it up.}}}
% I can use TeX or LaTeX to get the height of the saved box.
%\the\ht\tmpparbox % TeX
%\newlength{\tmpparboxht} % LaTeX
%\settoheight{\tmpparboxht}{\usebox{\tmpparbox}}
Here is the \string\savebox: \usebox{\tmpparbox}
\bigbreak
Target height: \the\ht\tmpparbox
\kern20pt\hrule\kern20pt
This is not a parbox. \fbox{\parbox[t][\the\ht\tmpparbox][t]{40mm}{This parbox is top aligned with top-aligned content. And more text to fill it up.}}
\bigbreak
This is not a parbox. \fbox{\parbox[b][\the\ht\tmpparbox][t]{40mm}{This parbox is bottom aligned with top-aligned content. And more text to fill it up.}}
\bigbreak
This is not a parbox. \fbox{\parbox[t][\the\ht\tmpparbox][c]{40mm}{This parbox is top aligned with center-aligned content. And more text to fill it up.}}
\bigbreak
This is not a parbox. \fbox{\parbox[t][\the\ht\tmpparbox][b]{40mm}{This parbox is top aligned with bottom-aligned content. And more text to fill it up.}}
\bigbreak
This is not a parbox. \fbox{\parbox[c][\the\ht\tmpparbox][t]{40mm}{This parbox is center aligned with top-aligned content. And more text to fill it up.}}
\bigbreak
\end{document}
\textheight
doesn't relate to the height+depth of a page as by design the depth is ignored so you get even bottom baselines.