# Automatically setting table row height

When creating a table, Latex sometimes doesn't fit the row height well, making the content intersect with the borders as in the following:

Notice how the first row is too short while the second looks good.

This is generated by the code:

\begin{tabular} {   | c | c | }
\hline
$\left(\frac{1}{2},\frac{1}{2}\right)$   & $(1,1)$   \\ \hline
$(1,1)$      &  $\left(\frac{1}{1+c},\frac{1}{1+c}\right)$    \\  \hline
\end{tabular}


Any ideas as to how to make Latex allocate enough space for the rows without explicit commands?

Perhaps the problem is not with the table but rather the parenthesis, so a solution to that (make the parenthesis around the contents of the first cell larger) would help as well.

You have three main solutions:

1. Use the cellspace package, which defines a minimal vertical spacing between the contents of a cell and the above or below cell (\cellspacetoplimit and \cellspacebottomlimit). You have to prefix the column specifier with the letter S, or C if you use siunitx.
2. Use the makecell package and the pair of commands \setcellgapes{some length} (in preamble) and \setcellgapes (for specific tables)
3. Use the booktabs package and its toprule,\(c)midrule and \bottomrule commands, which add some vertical (adjustable) spacing around them. No vertical rules in this case.

Here is a demo with your specific code. See the details in the documentation of the packages:

\documentclass{article}

\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage{makecell}
\setcellgapes{4pt}

\usepackage{booktabs}

\begin{document}
\begin{tabular} { | c | c | }
\hline
$\left(\frac{1}{2},\frac{1}{2}\right)$ & $(1,1)$ \\ \hline
$(1,1)$ & $\left(\frac{1}{1+c},\frac{1}{1+c}\right)$ \\ \hline
\end{tabular}
\begin{tabular} { | Sc | Sc | }
\hline
$\left(\frac{1}{2},\frac{1}{2}\right)$ & $(1,1)$ \\
\hline
$(1,1)$ & $\left(\frac{1}{1+c},\frac{1}{1+c}\right)$ \\
\hline
\end{tabular}
{\makegapedcells\begin{tabular} { | c | c | }
\hline
$\left(\frac{1}{2},\frac{1}{2}\right)$ & $(1,1)$ \\ \hline
$(1,1)$ & $\left(\frac{1}{1+c},\frac{1}{1+c}\right)$ \\ \hline
\end{tabular}}
\vskip1cm
\begin{tabular} {cc}
\toprule
$\left(\frac{1}{2},\frac{1}{2}\right)$ & $(1,1)$ \\
\midrule
$(1,1)$ & $\left(\frac{1}{1+c},\frac{1}{1+c}\right)$ \\
\bottomrule
\end{tabular}

\end{document}


Here is a cute trick. I like the results better than \arraystretch.

\documentclass{article}
\begin{document}

\fboxrule=0pt
\begin{tabular} {   | c | c | }
\hline
\fbox{$\left(\frac{1}{2},\frac{1}{2}\right)$}   & $(1,1)$   \\ \hline
$(1,1)$      &  \fbox{$\left(\frac{1}{1+c},\frac{1}{1+c}\right)$}    \\  \hline
\end{tabular}
\medskip
\end{document}

• You could consider reducing \tabcolsep to eat up the \fboxsep. – Steven B. Segletes Mar 31 '15 at 16:43
• @Steven B. Segletes - Or add a couple of \hspace{-\fboxsep}, if it is a problem. – John Kormylo Mar 31 '15 at 17:05