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.

I have a problem with vertically aligning content in a tabular environment:

\documentclass{article}
\begin{document}

\begin{tabular}{ p{2em} p{2em} }
    test & \begin{tabular}{l} s s s \\ s s s \end{tabular} \\
\end{tabular}

\end{document}

screenshot table example

Which as far as I understand the array documentation should give me two table cells which are top-aligned and have a with of 2em.

The thing is that if I don't have a table in the second cell but simply text then it works as intended:

\documentclass{article}
\begin{document}

\begin{tabular}{ p{2em} p{2em} }
    \hline
    test & s s s s s s s s s s s s s s s \\
    \hline
\end{tabular}

\end{document}

screenshot text example

What is the reason for the difference in appearance?

share|improve this question
3  
tabular and array are centred by default, you want [t] on the inner tabular so it aligns on its top row –  David Carlisle Sep 12 '12 at 19:00
    
thanks for the hint, it looks correct now, but I still don't get why the content of the right column does effect the alignment of the left one? Shouldn't they both be a \parbox[t] and therefore be lined up in a way that the parbox top aligns with the current text line? –  Andreas Wallner Sep 12 '12 at 19:06
1  
yes they are, the two colums align on the baselines of the top line, but in the first exampke the baseline of the first line is through the centre of the inner table –  David Carlisle Sep 12 '12 at 19:09
1  
@AndreasWallner: Consider the alignment specification [t] as placing an anchor point for that \parbox. Putting [t] for the left would not add any value, since it is only a single line. Meanwhile, it is required for the second entry, otherwise the anchor will be in the middle. –  Werner Sep 12 '12 at 19:10
    
@Werner thanks, I'll have to read up on that –  Andreas Wallner Sep 12 '12 at 19:14

1 Answer 1

up vote 9 down vote accepted

enter image description here

It's easier to see the baselines of the two columns if the second column has some additional text:

\documentclass{article}
\begin{document}

\begin{tabular}{ p{2em} p{7em} }
    test & s \begin{tabular}{l} first \\ second \end{tabular} s s s s s \\\hline
    test & s \begin{tabular}[t]{l} first \\ second \end{tabular} s s s s s \\
\end{tabular}

\end{document}

See in the second row the inner table aligns on its top row as [t] has been added, but in both cases the first column of the outer table is aligned with its baseline aligned with the baseline of the second column.

(Note the image in your question is not generated from the posted code)

share|improve this answer
    
thanks for the note, I had copied the wrong test code, fixed –  Andreas Wallner Sep 12 '12 at 19:38

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.