# \pbox vertical alignment

What's going on here, why are the TEXTs not aligned?

\documentclass{article}
\usepackage{pbox}

\begin{document}

\hrule
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Short}
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Long Text}
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Short}
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Long Text}
\hrule

\end{document}

-
Clearly pbox is not adjusting for the depth of g. Why not use a standard \parbox ? –  David Carlisle Jan 25 '13 at 12:02
The contents of each \pbox is pushed at the bottom, as requested by the final [b] argument. All boxes have the same total height, so this is what you get. Do you want \pbox[c][20pt][t] instead? –  egreg Jan 25 '13 at 12:05
Of course, the g, I should have seen that. @David: I use \pbox inside tikz to position a vertical line centered below the boxs. I don't know the widths. –  Frank Seifert Jan 25 '13 at 12:10
yes saw that now, I generated an example but egreg and Harish beat me to it, but I'd probably just use a simple 1 column tabular for that. For more general variable sized parbox varwidth package is probably more robust. –  David Carlisle Jan 25 '13 at 12:16
Thanks @David, I'll give it try –  Frank Seifert Jan 25 '13 at 12:18

g in Long has a depth where as in Short no letter has depth. This is why the misalignment comes. To correct it, you may add a \vphantom{g} to Short or \smash the Long (or only g).

\documentclass{article}
\usepackage{pbox}

\begin{document}

\hrule
\pbox[c][20pt][b]{\textwidth}{TEXT\\ \vphantom{g}Short}%
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Long Text}%
\pbox[c][20pt][b]{\textwidth}{TEXT\\ \vphantom{g}Short}%
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Long Text}%
\hrule
%
\bigskip
%
\hrule
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Short}%
\pbox[c][20pt][b]{\textwidth}{TEXT\\ \smash{Long} Text}%
\pbox[c][20pt][b]{\textwidth}{TEXT\\ Short}%
\pbox[c][20pt][b]{\textwidth}{TEXT\\ \smash{Long} Text}%
\hrule

\end{document}


-

If you want to disregard automatically the depth of the last line, you can use the varwidth package and a custom made command based on it:

\documentclass{article}
\usepackage{varwidth}

\newcommand{\spbox}{} % check whether it's already defined
\def\spbox#1#{\def\spboxtemp{#1}\spboxaux}% absorb the possible optional arguments
\newcommand\spboxaux[2]{%
\begingroup
\expandafter\varwidth\spboxtemp{#1}#2\par\kern-\prevdepth\endvarwidth
\endgroup}

\begin{document}

\hrule
\spbox[c][20pt][b]{\textwidth}{TEXT\\ Short}
\spbox[c][20pt][b]{\textwidth}{TEXT\\ Long Text}
\spbox[c][20pt][b]{\textwidth}{TEXT\\ Short}
\spbox[c][20pt][b]{\textwidth}{TEXT\\ Long Text}
\hrule

\end{document}


-