# Spacing of rows in a table [duplicate]

I am using package tabular but encounter a problem with the spacing of rows, I would like to have more space at the top and at the bottom of each formula. I already looked at older posts dealing with this issue and they suggested to use arraystretch but it stretches all the rows (I don't want first row to be stretched for example) but most importantly unequally (there is more space at the top than at the bottom).

This is what my table currently looks like:

This is what arraystretch (with factor 3) do to it:

In both cases it is not aesthetically pleasing. And I can't seem to find any simple solution to my problem.

Here's my code:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[french]{babel}
\usepackage{array}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\begin{document}

\begin{center}
\begin{tabular}{|c|c|c|}
\hline
Nom de la méthode & Formule de majoration de l'erreur & Ordre de convergence \\
\hline
Rectangles à gauche & $|E_h^{RG}(f)| \leq \dfrac{h}{2} (\beta-\alpha)\lVert f'\rVert_{\infty}^{[a,b]}$ & 1 \\
\hline
Point Milieu &  $|E_h^{PM}(f)| \leq \dfrac{h^2}{24} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$ & 2 \\
\hline
Trapèzes & $|E_h^T(f)| \leq \dfrac{h^2}{12} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$ & 2 \\
\hline
Simpson & $|E_h^S(f)| \leq \dfrac{h^4}{2880} (\beta-\alpha)\lVert f^{(4)}\rVert_{\infty}^{[a,b]}$ & 4 \\
\hline
\end{tabular}
\end{center}

\end{document}

• Adding \usepackage{makecell} \setcellgapes{6pt} to the preamble and \makegapedcells beofr your tabular should help. You can of course adjust the amount to of added space to your needs. Nov 4, 2021 at 19:57
• Thanks! That's really helpful and simple, it works as intended.
– Axel
Nov 4, 2021 at 20:02
• The suggested duplicate - Column and row padding in tables - contains reference to cellspace that is covered in the currently-accepted answer.
– Werner
Nov 4, 2021 at 21:37
• @Werner I'm sorry I made a duplicate, I was lost in the huge amount of answers. Thank you for the linked post and the reference.
– Axel
Nov 4, 2021 at 22:15

The tool for that is cellspace, which defines a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letterS (or C if you load siunitx, or any letter you please with loadtime option [column=…]

\documentclass[a4paper]{book}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}

\begin{document}

\begin{table}[htb]
\centering
\begin{tabular}{|Sc|Sc|Sc|}
\hline
Nom de la méthode & Formule de majoration de l'erreur & Ordre de convergence \\
\hline
Rectangles à gauche & $|E_h^{RG}(f)| \leq \dfrac{h}{2} (\beta-\alpha)\lVert f'\rVert_{\infty}^{[a,b]}$ & 1 \\
\hline
Point Milieu & $|E_h^{PM}(f)| \leq \dfrac{h^2}{24} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$ & 2 \\
\hline
Trapèzes & $|E_h^T(f)| \leq \dfrac{h^2}{12} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$ & 2 \\
\hline
Simpson & $|E_h^S(f)| \leq \dfrac{h^4}{2880} (\beta-\alpha)\lVert f^{(4)}\rVert_{\infty}^{[a,b]}$ & 4 \\
\hline
\end{tabular}
\end{table}

\end{document}


• Thank you, this is concise and clear. This answer is very useful (+1)
– Axel
Nov 4, 2021 at 20:24

The most elegant typographic approach to keep stuff from getting too close to horizontal lines in a table? Easy: Don't use horizontal lines!

Here's a tabularx-based implementation of this idea.

\documentclass{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage{lmodern}

\usepackage{amssymb,mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\usepackage{tabularx,booktabs,ragged2e}
\newcolumntype{C}{>{\Centering}X} $centered version of 'X' col. type \newcolumntype{L}{>{$\displaystyle}l<{$}} % automatic math mode \begin{document} \noindent \begin{tabularx}{\textwidth}{@{} l >{$\displaystyle}l<{$} C @{}} \toprule Nom de la méthode &$Formule de majoration de l'erreur$& Ordre de convergence \\ \midrule Rectangles à gauche & \abs{E_h^{\mathit{RG}}(f)} \le \frac{h}{2} (\beta-\alpha) \norm[\big]{f'}_{\infty}^{[a,b]} & 1 \\ \addlinespace Point Milieu & \abs{E_h^{\mathit{PM}}(f)} \le \frac{h^2}{24} (\beta-\alpha) \norm[\big]{f^{(2)}}_{\infty}^{[a,b]} & 2 \\ \addlinespace Trapèzes & \abs{E_h^T(f)} \le \frac{h^2}{12} (\beta-\alpha) \norm[\big]{f^{(2)}} _{\infty}^{[a,b]} & 2 \\ \addlinespace Simpson & \abs{E_h^S(f)} \le \frac{h^4}{2880} (\beta-\alpha) \norm[\big]{f^{(4)}} _{\infty}^{[a,b]} & 4 \\ \bottomrule \end{tabularx} \end{document}  • Not was I was originally looking for, but thank you for the extra explanations, that's instructive and helpful! – Axel Nov 4, 2021 at 20:35 Here are three possibilities using makecell, nicematrix or tabularray: \documentclass{article} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage[french]{babel} \usepackage{array} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} %%% first example %%% \usepackage{makecell} \setcellgapes{4pt} %%% second example %%% \usepackage{nicematrix} %%% third example %%% \usepackage{tabularray} \begin{document} \begin{center} \makegapedcells \begin{tabular}{|c|c|c|} \hline Nom de la méthode & Formule de majoration de l'erreur & Ordre de convergence \\ \hline Rectangles à gauche &$|E_h^{RG}(f)| \leq \dfrac{h}{2} (\beta-\alpha)\lVert f'\rVert_{\infty}^{[a,b]}$& 1 \\ \hline Point Milieu &$|E_h^{PM}(f)| \leq \dfrac{h^2}{24} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$& 2 \\ \hline Trapèzes &$|E_h^T(f)| \leq \dfrac{h^2}{12} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$& 2 \\ \hline Simpson &$|E_h^S(f)| \leq \dfrac{h^4}{2880} (\beta-\alpha)\lVert f^{(4)}\rVert_{\infty}^{[a,b]}$& 4 \\ \hline \end{tabular} \end{center} \begin{center} \begin{NiceTabular}[hvlines, cell-space-limits=4pt]{ccc} Nom de la méthode & Formule de majoration de l'erreur & Ordre de convergence \\ Rectangles à gauche &$|E_h^{RG}(f)| \leq \dfrac{h}{2} (\beta-\alpha)\lVert f'\rVert_{\infty}^{[a,b]}$& 1 \\ Point Milieu &$|E_h^{PM}(f)| \leq \dfrac{h^2}{24} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$& 2 \\ Trapèzes &$|E_h^T(f)| \leq \dfrac{h^2}{12} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$& 2 \\ Simpson &$|E_h^S(f)| \leq \dfrac{h^4}{2880} (\beta-\alpha)\lVert f^{(4)}\rVert_{\infty}^{[a,b]}$& 4 \\ \end{NiceTabular} \end{center} \begin{center} \SetTblrInner{rowsep=4pt} \begin{tblr}{colspec={ccc}, hlines, vlines} Nom de la méthode & Formule de majoration de l'erreur & Ordre de convergence \\ Rectangles à gauche &$|E_h^{RG}(f)| \leq \dfrac{h}{2} (\beta-\alpha)\lVert f'\rVert_{\infty}^{[a,b]}$& 1 \\ Point Milieu &$|E_h^{PM}(f)| \leq \dfrac{h^2}{24} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$& 2 \\ Trapèzes &$|E_h^T(f)| \leq \dfrac{h^2}{12} (\beta-\alpha)\lVert f^{(2)}\rVert_{\infty}^{[a,b]}$& 2 \\ Simpson &$|E_h^S(f)| \leq \dfrac{h^4}{2880} (\beta-\alpha)\lVert f^{(4)}\rVert_{\infty}^{[a,b]}\$ & 4 \\
\end{tblr}
\end{center}
\end{document}

• I have trouble running nicematrix package for unknown reason. But the first method is very efficient, thank you!
– Axel
Nov 4, 2021 at 20:26