# Vertical alignment in 'tabular'

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}


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}


What is the reason for the difference in appearance?

-
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
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
@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

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)

-