# Top alignment of cell content in tabularx

I would like to align the content of each cell (of the first column) to the top. The approaches presented here did not apply. Maybe it has something to do with die tabular-environment inside the tabluarx-environment?

How it looks like

How I would like it to look like

MWE

\documentclass{article}
\usepackage{tabularx,booktabs}

\begin{document}

\begin{tabularx}{\textwidth}{lX}
\toprule
Mittel    & technische Details\\
\midrule
%first row of tabularx
Laptop      &
\begin{tabular}{ll}
MacBook Pro & \\
Baujahr 2010 & \\
Prozessor & 2.4 GHz Intel Core 2 Duo \\
Speicher & 4 GB 1067 MHz DDR3 \\
Software & Mac OS X Lion 10.7.5 (11G63)
\end{tabular}\\[3em]
%second row of tabularx
Programmierumgebung          &
\begin{tabular}{ll}
Version & 8.0.4.0 \\
Plattform & Mac OS x86 (32-bit, 64-bit Kernel)
\end{tabular}\\
\bottomrule
\end{tabularx}

\end{document}

-

You can make the inner tabulars top align by using [t] It may just be an artifact of your small example but tabularx can do nothing to help here as the inner tabular is fixed to its natural width so can not reflow to whatever width the X column specifies.

\documentclass{article}
\usepackage{tabularx,booktabs}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{lX}
\toprule
Mittel    & technische Details\\
\midrule
%first row of tabularx
Laptop      &
\begin{tabular}[t]{ll}
MacBook Pro & \\
Baujahr 2010 & \\
Prozessor & 2.4 GHz Intel Core 2 Duo \\
Speicher & 4 GB 1067 MHz DDR3 \\
Software & Mac OS X Lion 10.7.5 (11G63)
\end{tabular}\\[3em]
%second row of tabularx
Programmierumgebung          &
\begin{tabular}[t]{ll}
Version & 8.0.4.0 \\
Plattform & Mac OS x86 (32-bit, 64-bit Kernel)
\end{tabular}\\
\bottomrule
\end{tabularx}

\end{document}

-
I've noticed there's a significant difference between the X column type and the "older" l and p{<width>} column types: If there's a tabular environment in a row and X column, it's necessary to suppress the whitespace at the left edge of the environment explicitly, by inserting @{}, in order to get its contents to line up with other cells in the same column that are not tabulars. (See also the output of your MWE.) Inserting @{} isn't needed if the tabular environment occurs in a column of type p or l. Is this a "feature" of the tabularx environment? –  Mico Mar 21 '13 at 13:41
@Mico Not really any different: X is p by the time that the table is typeset it just calculates a width and then literally generates a p{...} column specification and calls a normal tabular. –  David Carlisle Mar 21 '13 at 13:45

Why not use a single tabularx environment instead of one inside a tabular?

\begin{tabularx}{\textwidth}{llX}
\toprule
Mittel              & technische Details & \\
\midrule
Laptop              & MacBook Pro  & \\
& Baujahr 2010 & \\
& Prozessor    & 2.4 GHz Intel Core 2 Duo \\
& Speicher     & 4 GB 1067 MHz DDR3 \\
& Software     & Mac OS X Lion 10.7.5 (11G63) \\[3em]
Programmierumgebung & Version      & 8.0.4.0 \\
& Plattform    & Mac OS x86 (32-bit, 64-bit Kernel)\\
\bottomrule
\end{tabularx}


-
Maybe the easiest way. –  John Mar 21 '13 at 12:39

One can specify the vertical alignment -- top, middle (default), and bottom -- of a tabular environment via an optional argument. In the code below, I use [t] (for "top" alignment). Note that it's also necessary now to suppress explicitly, via a @{} directive, the whitespace that's otherwise inserted at the left edge of the cell when using the X column type for a cell that contains a tabular environment.

\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{lX}
\toprule
Mittel  & technische Details\\
\midrule
%first row of tabularx
Laptop    &
\begin{tabular}[t]{@{}ll}
% use [t] alignment specifier, and @{} to
% suppress extra whitespace at left edge
MacBook Pro & \\
Baujahr 2010 & \\
Prozessor & 2.4 GHz Intel Core 2 Duo \\
Speicher & 4 GB 1067 MHz DDR3 \\
Software & Mac OS X Lion 10.7.5 (11G63)
\end{tabular}\\[5em]
%second row of tabularx
Programmierumgebung      &
\begin{tabular}[t]{@{}ll}
Version & 8.0.4.0 \\
Plattform & Mac OS x86 (32-bit, 64-bit Kernel)
\end{tabular}\\
\bottomrule
\end{tabularx}
\end{document}

-