[Tex/LaTex] Vertical alignment problem with \arraystretch and m column definition

tablesvertical alignment

For some reason, in m{} columns, once \arraystretch pushes row height above the text height, the text ceases to be absolutely aligned. Instead, the first line is centered vertically and the rest fall below it. Any thoughts on why this is and/or how to fix it?

\documentclass{article}
\usepackage{array}
\begin{document}
\renewcommand{\arraystretch}{4}
\noindent\begin{tabular}{m{3in}c}
    \hline
    [19:21] time to take the tree outside\newline
    [19:21] but I just let him back in! & 
    [19:21] time to take the tree outside\\
\hline
\end{tabular}
\end{document}  

Okay, here's the more complete version.

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\newcommand{\ccol}{\centering\arraybackslash}
\renewcommand{\tabularxcolumn}[1]{>{\ccol}m{#1}}
\begin{document}
\renewcommand{\arraystretch}{4}
\noindent\begin{tabularx}{\textwidth}{m{2.1in}X}
    \hline
    [19:21] time to take the tree outside\newline
    [19:21] but I just let him back in! & 
    [19:21] time to take the tree outside\\
    \hline
\end{tabularx}

\end{document}

Best Answer

This is the default behaviour when using \arraystretch. The reason for this is that the contents inside a tabular (or array) is set with the traditional \baselineskip in mind, with the additional horizontal rule, making it seem like the entries are not vertically centered within each row. Modifying (increasing) \arraystretch exaggerates this apparent mis-alignment.

I would suggest inserting blank lines above/below the rows that need "air" like in the following MWE:

enter image description here

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\setlength{\parindent}{0pt}% No paragraph indent
\newcommand{\ccol}{\centering\arraybackslash}
\renewcommand{\tabularxcolumn}[1]{>{\ccol}m{#1}}
\begin{document}
\textbullet~No modification of \verb|\arraystretch|: \par
  \begin{tabularx}{\linewidth}{m{2.1in}X}
    \hline
    [19:21] time to take the tree outside\newline
    [19:21] but I just let him back in! & 
    [19:21] time to take the tree outside\\
    \hline
  \end{tabularx} \par\medskip

\textbullet~\verb|\arraystretch=4| \par
  \renewcommand{\arraystretch}{4}%
  \begin{tabularx}{\linewidth}{m{2.1in}X}
    \hline
    [19:21] time to take the tree outside\newline
    [19:21] but I just let him back in! & 
    [19:21] time to take the tree outside\\
    \hline
  \end{tabularx} \par\medskip

\textbullet~\verb|\arraystretch=1| \par
  \renewcommand{\arraystretch}{1}%
  \begin{tabularx}{\linewidth}{m{2.1in}X}
    \hline \\ \\\mbox{}%
    [19:21] time to take the tree outside\newline
    [19:21] but I just let him back in! & 
    [19:21] time to take the tree outside \\ \\ \\
    \hline
  \end{tabularx}
\end{document}

Note that using square brackets to start a new line in a tabular could lead to problems when inserting empty rows, since \\ is a control sequence that takes an optional argument: \\[<len>]. To avoid this, I've inserted an empty \mbox{} after \\ (in the last tabular) otherwise TeX would try to perform \\[19:21], and 19:21 is not a valid TeX length.