125

I couldn't find any option that lets me expand the vertical space between rows in tabular environment. For example,

\begin{tabular}{c c}
    $f^{(n)}(x)$ & $f^{(n)}(0)$ \\
    $-2xe^{-x^{x^{x^2}}}$ & 0 
\end{tabular}

This looks awkward because of the powers of x. I wonder if there is an option to expand the vertical spaces between these rows?

David Carlisle
  • 757,742
roxrook
  • 9,907

5 Answers5

175

You have at least three options here:

  • Increasing the array stretch factor using \renewcommand{\arraystretch}{<factor>} where <factor> is a numeric value:

    \documentclass{article}
    \begin{document}
    \renewcommand{\arraystretch}{2}
    \begin{tabular}{c c}
      $f^{(n)}(x)$ & $f^{(n)}(0)$ \\\hline
      $-2xe^{-x^{x^{x^2}}}$ & 0
    \end{tabular}
    \end{document}
    

    enter image description here

  • Explicitly specifying the row skip using \\[<len>] where <len> is any length:

    \documentclass{article}
    \begin{document}
    \begin{tabular}{c c}
      $f^{(n)}(x)$ & $f^{(n)}(0)$ \\[1cm] \hline
      $-2xe^{-x^{x^{x^2}}}$ & 0
    \end{tabular}
    \end{document}
    

    enter image description here

  • Modifying the array package's \extrarowheight length using \setlength{\extrarowheight}{<len>}, where <len> is any length:

    \documentclass{article}
    \usepackage{array}% http://ctan.org/pkg/array
    \begin{document}
    \setlength{\extrarowheight}{20pt}
    \begin{tabular}{c c}
      $f^{(n)}(x)$ & $f^{(n)}(0)$ \\\hline
      $-2xe^{-x^{x^{x^2}}}$ & 0
    \end{tabular}
    \end{document}
    

    enter image description here

In the above examples, the \hline was used to illustrate the effect of the different styles used. The choice depends on the specific usage/typesetting of the tabular within your document.

Finally, if the contents of your entire tabular is math, you could typeset it in an array environment:

\[
  \begin{array}{c c}
    f^{(n)}(x) & f^{(n)}(0) \\
    -2xe^{-x^{x^{x^2}}} & 0
  \end{array}
\]
Werner
  • 603,163
  • Thanks a lot for the answer as well as many other alternative solutions ;) – roxrook Aug 28 '11 at 02:10
  • How can I define the row skip (\[1cm] in your example) with a multirow cell in my table? I would like to enlarge the space between all other cells which are spanned by the multirow, but defining the row skip just like you do it does not work. – Rob Feb 22 '16 at 13:13
  • @Rob: My suggestion would be to ask a new question with a clear demonstration of what you have and what you're after. You can then link to this post if you wish to provide some additional context. – Werner Feb 22 '16 at 17:11
  • 2
    Problem solved. \[1cm] was just not big enough to see any difference... – Rob Feb 23 '16 at 09:08
  • I had a table with many rows and I wanted to increase the space of only one row. The best solution for me in this case was to insert a vertical strut of the type \rule{0pt}{1.2\normalbaselineskip}, as mentioned here http://tex.stackexchange.com/questions/65127/extra-vertical-space-after-hline-causes-a-gap-in-the-right-border-of-an-array – pietro Aug 03 '16 at 14:38
  • Careful if you are using matrices then \renewcommand{\arraystretch}{2} will stretch those too. To not effect the matrices, use \\[1em] to mark the row end within the table instead. – user3613932 Jun 10 '21 at 17:19
  • @user3613932: Yes, or provide some scoping via a group to limit the adjustment: {...} or \bgroup...\egroup or \begingroup...\endgroup. – Werner Jun 10 '21 at 17:24
11

You can use booktabs. Left is the output using \midrule, right the one with the \hline approach.

The left table is also improved by stating \displaystyle that uses less cramped superscripts.

\documentclass{article}
\usepackage{array,booktabs}
\newcolumntype{C}{>{$\displaystyle}c<{$}}

\begin{document}

\begin{tabular}{CC}
f^{(n)}(x) & f^{(n)}(0) \\
\midrule
-2xe^{-x^{x^{x^2}}} & 0
\end{tabular}
\qquad
\begin{tabular}{cc}
$f^{(n)}(x)$ & $f^{(n)}(0)$ \\
\hline
$-2xe^{-x^{x^{x^2}}}$ & 0
\end{tabular}

\end{document}

enter image description here

egreg
  • 1,121,712
7

For multi-rows, you can try this

\documentclass{article}
\usepackage{array}% 
\begin{document}
\begin{tabular}{c c}
  $f^{(n)}(x)$ & $f^{(n)}(0)$ \\[1cm]
  $-2e^{-x^{x^{x}}}$ & 0\\[1cm]
  $2x&\frac{x}{2}\\[1cm] 
.
.
.
\end{tabular}
\end{document}
egreg
  • 1,121,712
6

Eventually, the options any LaTeX beginner desired were born!

The new (May 2021) package tabularray has two options to set the space before and after the table rows: abovesep and belowsep of the parameter rows!

The same package have also analogous options for columns, together with many other useful parameters and column types.

The environment tblr works both on math and text mode.

Thanks to Jianrui Lyu (the author)!

\documentclass{book}

\usepackage{tabularray}

\begin{document} A pure \texttt{tblr} it's already OK [ \begin{tblr}{c c} f^{(n)}(x) & f^{(n)}(0) \ -2xe^{-x^{x^{x^2}}} & 0 \end{tblr} ] but you can even set the space you need: [ \begin{tblr}{cells={c},rows = {abovesep=6pt,belowsep=8pt},} f^{(n)}(x) & f^{(n)}(0) \ -2xe^{-x^{x^{x^2}}} & 0 \end{tblr} ] You can set the spacing also for one row only, indicating the number of the row with \verb|row{<number>}|: [ \begin{tblr}{cells={c},row{2}= {abovesep=4pt},} f^{(n)}(x) & f^{(n)}(0) \ -2xe^{-x^{x^{x^2}}} & 0 \end{tblr} ]

Here I add \verb|hline|s to better show the spacing: [ \begin{tblr}{c c} \hline f^{(n)}(x) & f^{(n)}(0) \ \hline -2xe^{-x^{x^{x^2}}} & 0 \ \hline \end{tblr} ] [ \begin{tblr}{cells={c},rows = {abovesep=6pt,belowsep=8pt},} \hline f^{(n)}(x) & f^{(n)}(0) \ \hline -2xe^{-x^{x^{x^2}}} & 0 \ \hline \end{tblr} ] [ \begin{tblr}{cells={c},row{2}= {abovesep=4pt},} \hline f^{(n)}(x) & f^{(n)}(0) \ \hline -2xe^{-x^{x^{x^2}}} & 0 \ \hline \end{tblr} ]

\end{document}

enter image description here

CarLaTeX
  • 62,716
4

You have another option here - specifying row colors:

\documentclass{article}
\usepackage{color, colortbl}
%Light gray:
\definecolor{Gray}{gray}{0.9}

%Light cyan:
\definecolor{LightCyan}{rgb}{0.88,1,1}

\begin{document}
\renewcommand{\arraystretch}{2}
\begin{tabular}{c c}
\rowcolor{Gray}
$f^{(n)}(x)$ & $f^{(n)}(0)$ \\\hline
\rowcolor{LightCyan}
$-2xe^{-x^{x^{x^2}}}$ & 0
\end{tabular}
\end{document}

Which gives you

  • 2
    Welcome to TeX.SX! Not really an answer to the question, but an interesting alternative. – egreg Oct 16 '16 at 14:11