# Vertical alignment of a tabularx cell

I have a tabularx table with:

• a variable width column X on the left
• a cell with a nested tabular table on the right

Like so:

\begin{tabularx}{\textwidth}{ | X | c | }
\lipsum[1-1]
&
\begin{tabular}{rl}
test&test\\
test&test\\
test&test\\
test&test\\
test&test\\
test&test\\
\end{tabular}
\end{tabularx}


Now the problem I have is that for some reason it looks like this:

And I want it to look like this:

You are aligning the top line of the paragraph with the centre of the tabular.

Use

\begin{tabular}[t]


so that the top line of the tabular is taken as the alignment point, which will then align with the top line of the paragraph in the first column.

You can do that with a simpler syntax if you use the makecellpackage, which allows for a common formatting, vertical/horizontal alignment and line breaks in cells introduced by the \makecell command. A small patch allows to have the vertical and horizontal alignment of the cell as an optional argument (default is cc – vertically and horizontally centred). In addition it can provide some vertical padding of cells:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array, tabularx}
\usepackage{makecell}
\setcellgapes{3pt}
\let\oldmakecell\makecell
\usepackage{lipsum}

\begin{document}

\begin{table}[h]
\makegapedcells
\begin{tabularx}{\textwidth}{ | X | rl | }
\lipsum[1-1]\leavevmode\vspace*{-\baselineskip}
& \makecell[tr]{test\\test\\test\\test\\test\\tests}
& \makecell[tl]{test\\test\\test\\test\\test\\tests}\\
\end{tabularx}
\end{table}

\end{document}


I think you need to make two adjustments to the code:

• First, as already noted by David Carlisle, you need to add the [t] position specifier to the inner tabular environment.

• Second, you need to remove the extra whitespace that's surrounding the inner tabular -- remember that the c column type of the outer tabularx environment already provides whitespace (in the amount of \tabcolsep). No need to duplicate this. I suggest you insert @{} directives to prevent the insertion of extra whitespace.

To summarize, the inner tabular environment should be set up as follows:

\begin{tabular}[t]{@{} rl @{}}


\documentclass{article}
\usepackage{tabularx,lipsum}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{ | X | c | }
\lipsum*[1]
&
\begin{tabular}[t]{@{} rl @{}}
test&test\\
test&test\\
test&test\\
test&test\\
test&test\\
test&test\\
\end{tabular}
\end{tabularx}
\end{document}