[Tex/LaTex] Vertical alignment in ‘tabular’

tablesvertical alignment

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?

Best Answer

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)