6
\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}

enter image description here

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

2 Answers 2

2
\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}

enter image description here

5

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}

enter image description here

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.

enter image description here

6
  • Please explain the mathematical aspect of your magic numbers. Commented Feb 5, 2014 at 13:41
  • @CodeMocker Explanation added. Commented Feb 5, 2014 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). Commented Feb 5, 2014 at 14:21
  • @DavidCarlisle Thanks for the tip. I didn't know how else to overcome that deficiency. Let me work to fix it. Commented Feb 5, 2014 at 14:41
  • @DavidCarlisle I found, in addition, that fragile commands don't need to be protected with !, unlike @. Thanks again. Commented Feb 5, 2014 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .