Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

enter image description here

\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}
share|improve this question
1  
Clearly pbox is not adjusting for the depth of g. Why not use a standard \parbox ? –  David Carlisle Jan 25 '13 at 12:02
2  
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
1  
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

2 Answers 2

up vote 6 down vote accepted

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}

enter image description here

share|improve this answer

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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.