Row height and cell padding in LaTeX tables (arraystretch, tabcolsep)
\renewcommand{\arraystretch}{1.5} makes every row 1.5 times as high. \setlength{\tabcolsep}{12pt} sets the space to the left and right of every column; the default is 6 pt.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{array}
\usepackage{booktabs}Make all rows higher
\arraystretch is a factor with the default 1. Set it inside the table environment so that the change ends with the table.
\begin{table}
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|l|r|}
\hline
Item & Price \\
\hline
Apple & 0.50 \\
\hline
Banana & 0.25 \\
\hline
\end{tabular}
\end{table}Add space after one row
A length in brackets after \\ adds that much space below the row: \\[6pt]. In a booktabs table, \addlinespace between two rows does the same and also takes a length: \addlinespace[6pt].
\begin{tabular}{lr}
\toprule
Item & Price \\
\midrule
Apple & 0.50 \\[6pt]
Banana & 0.25 \\
Cherry & 0.10 \\
\addlinespace
Total & 0.85 \\
\bottomrule
\end{tabular}Change the space between columns
\tabcolsep is half the space between two columns, because every column gets it on both sides. @{} in the column argument removes this space at that place, here at the left and right edge of the table.
\begin{table}
\centering
\setlength{\tabcolsep}{12pt}
\begin{tabular}{@{}lrr@{}}
\toprule
Item & Price & Stock \\
\midrule
Apple & 0.50 & 120 \\
Banana & 0.25 & 80 \\
\bottomrule
\end{tabular}
\end{table}Add space above the text only
In a table with \hline, capital letters come close to the line above them. The length \extrarowheight from the array package adds space above the text of every row and leaves the space below unchanged.
\begin{table}
\centering
\setlength{\extrarowheight}{3pt}
\begin{tabular}{|l|r|}
\hline
Item & Price \\
\hline
Apple & 0.50 \\
\hline
\end{tabular}
\end{table}Pitfalls
\arraystretchalso stretchesarray,matrixandpmatrixin formulas. A change in the preamble applies to all of them.- In a
pcolumn with several lines,\arraystretchadds space above the first and below the last line only. The distance between the lines of the cell stays the same.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
array - Package
booktabs - How-to Set the column width of a table in LaTeX
- How-to Line break in a table cell in LaTeX
- How-to Line spacing in LaTeX