0

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

enter image description here

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.

2

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}
\qquad
\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}
\qquad
{\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} 

enter image description here

2

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

fbox table

\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
  • 1
    @Steven B. Segletes - Or add a couple of \hspace{-\fboxsep}, if it is a problem. – John Kormylo Mar 31 '15 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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