# How to vertically center cell content when its height is stretched by \arraystretch?

\documentclass[preview,border=12pt,varwidth]{standalone}

\renewcommand\arraystretch{5}
\begin{document}

\begin{tabular}{|c|c|}\hline
Time & Monday \\\hline
16:00-16:30 &\\\hline
16:30-17:00 &\\\hline
\end{tabular}

\end{document}


How to vertically center cell content when its height is stretched by \arraystretch?

-

\documentclass[12pt]{article}
\usepackage[thinlines]{easytable}
\begin{document}

\begin{TAB}(r,1cm,2cm)[5pt]{|c|c|}{|c|c|c|}% (rows,min,max)[tabcolsep]{columns}{rows}
Time         & Monday \\
16:00--16:30 & f      \\
16:30--17:00 & f
\end{TAB}

\end{document}


-

In lieu of \arraystretch, I add a homemade strut to the beginning of each row in column 1.

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage{array}
%\renewcommand\arraystretch{5}
\def\mystrut{\rule[-6ex]{0ex}{14ex}}
\begin{document}
\begin{tabular}{|!{\mystrut}c|c|}\hline
Time & Monday \\\hline
16:00-16:30 &\\\hline
16:30-17:00 &\\\hline
\end{tabular}
\end{document}


To explain what is happening, \mystrut is just a zero width rule that stretches from 6ex below the baseline to 8ex above the baseline (a height of 14ex). By placing it among text, it creates a lot of room above and below the text. I could manually add it to each row of the table, which is a little extra work. To avoid that, I used the !{} facility of the array package to achieve the result (hat tip to David Carlisle). This ! feature executes the bracketed argument on every row of the tabular automatically (while retaining the \tabcolsep, unlike @{}).

Just to demonstrate what \mystrut looks like in this context, I below create a nearly identical macro, \visiblestrut defined as {\rule[-6ex]{1ex}{14ex}} so that it is 1ex wide (instead of 0), and manually place it before the word Monday. Here is the result. You can see that it is such a strut that creates the space above and below the actual text.

-
Please explain the mathematical aspect of your magic numbers. – kiss my armpit Feb 5 '14 at 13:41
+1 for your effort. :-) – kiss my armpit Feb 5 '14 at 13:47
@CodeMocker Explanation added. – Steven B. Segletes Feb 5 '14 at 13:49
Would be +1 f you replace @{~ by !{ (using array package. ! is like @ but doesn't remove tabcolsep space. As is you remove tabcolsep then add ~ which isn't the same length (normally). – David Carlisle Feb 5 '14 at 14:21
@DavidCarlisle Thanks for the tip. I didn't know how else to overcome that deficiency. Let me work to fix it. – Steven B. Segletes Feb 5 '14 at 14:41