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

tablesvertical alignment

I have the code:

\documentclass{article}
\usepackage[a5paper]{geometry}
\begin{document}
\begin{tabular}{ | c | }
  \hline
  top\\[8ex]
  \hline
  center\\[8ex]
  \hline
  bottom\\[8ex]
  \hline
\end{tabular}
\end{document}

Gives this:

enter image description here

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

Best Answer

A somewhat more automated solution, which doesn't require the user to specify the width of the \parbox manually. The new command \parboxc accepts three arguments:

  1. the vertical alignment specification: t, c, or b;
  2. the height of the \parbox;
  3. the contents of the \parbox.

enter image description here

\documentclass{article}
\usepackage[a5paper]{geometry}

\newlength\mytemplength

\newcommand\parboxc[3]{%
    \settowidth{\mytemplength}{#3}%
    \parbox[#1][#2]{\mytemplength}{\centering #3}%
}

\begin{document}
\begin{tabular}{ | c | }
  \hline
  \parboxc{t}{8ex}{top}\\
  \hline
  \parboxc{c}{8ex}{center}\\
  \hline
  \parboxc{b}{8ex}{bottom}\\
  \hline
\end{tabular}
\end{document}