Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted
\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

share|improve this answer

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

share|improve this answer
    
Please explain the mathematical aspect of your magic numbers. –  Who is crazy first Feb 5 at 13:41
    
+1 for your effort. :-) –  Who is crazy first Feb 5 at 13:47
    
@CodeMocker Explanation added. –  Steven B. Segletes Feb 5 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 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 at 14:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.