[Tex/LaTex] Vertical alignment in tabular cells with variable height

tablesvertical alignment

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:

enter image description here

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?

Best Answer

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}

enter image description here