# Vertical alignment in tabular cells with variable height

I have the code:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tabularx}
\usepackage{lipsum}
\begin{document}
\begin{tabularx}{\textwidth}{ | X | c | }
\hline
\lipsum[1] & top\\
\hline
\lipsum[1] & center\\
\hline
\lipsum[1] & bottom\\
\hline
\end{tabularx}
\end{document}


Gives this:

The top row is already aligned top. How can I vertically align the center row at the center? And the bottom row at the bottom?

The vertical adjustment of the row "c" is related to the definition of the columntype X which uses the specifier p.

You need m for a centered adjustment and b for bottom. This can be achieved by \multicolumn, whereby the line width must be saved (I don't know a good solution).

Here is an example:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tabularx}
\usepackage{lipsum}
\begin{document}

\begin{tabularx}{\textwidth}{ | X | c | }
\hline
\lipsum*[1]\xdef\tempwidth{\the\linewidth} & top\\\hline
\multicolumn{1}{|m{\tempwidth}|}{\lipsum*[1]} & center\\\hline
\multicolumn{1}{|b{\tempwidth}|}{\lipsum*[1]} & bottom\\\hline
\end{tabularx}
\end{document}


• @MarcoDaniel Why column c vertical alignment is defined by changing column X? – user4035 May 7 '13 at 19:24
• @user4035: Because the column type X is responsible for the baseline. – Marco Daniel May 7 '13 at 19:26
• @MarcoDaniel What if we have 3 columns: X|c|c. And want the 1-st c to be top aligned, and 2-nd c to be bottom aligned? – user4035 May 7 '13 at 19:31
• @user4035: you can use the same trick or use David's trick – Marco Daniel May 7 '13 at 19:49
• @Marco May this changed over they year but based on my tests you are wrong. The the column is of type X is irrelevant. The important fact is that it contains the large multi-line text. – Robert Sep 5 '19 at 15:02

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{tabularx}
\usepackage{lipsum}
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{ | X | c | }
\hline
\lipsum[1] & top\\
\hline
\noindent\parbox[c]{\hsize}{\lipsum[1]} & center\\
\hline
\noindent\parbox[b]{\hsize}{\lipsum[1]} & bottom\\
\hline
\end{tabularx}

\end{document}

• I absolutely love this simple solution, but for my liking there should be a bit of empty space between the cells. When I applied this to my table the cells are so close to each other that it looks kinda awkward. Is there any way to add a bit of empty space on the top and bottom of the cell? – Cadbon Apr 4 '15 at 14:43
• @Cadbon \renewcommand\arraystretch{2} or whatever number works for you – David Carlisle Apr 4 '15 at 15:02
• Unfortunately I couldn't solve my issues with that method as my top row has only one row of text and the arraystretch command stretches all cells. This means that my top row only has a single row of text but a very large cell which looks silly. – Cadbon Apr 6 '15 at 10:22
• Any idea how I can center the lipsum text horizontally with this? I tried \parbox[c][][c] but that doesn't seem to help... – gghuffer Oct 5 '15 at 2:05
• @gghuffer as in any parbox or p or X column,, just use \centering – David Carlisle Oct 5 '15 at 6:58

Another way, using a minipage environment instead of a tabularx package:

\documentclass{article}
\usepackage{lipsum}
\usepackage[a4paper]{geometry}
\begin{document}

\begin{tabular}{|l|c|}
\hline
\begin{minipage}[t]{0.85\textwidth}\lipsum[1]\end{minipage} & top\\
\hline
\begin{minipage}{0.85\textwidth}\lipsum[1]\end{minipage} & center\\
\hline
\begin{minipage}[b]{0.85\textwidth}\lipsum[1]\end{minipage} & bottom\\
\hline
\end{tabular}

\end{document}