Add padding to columns and rows in a table in LaTeX
In this tutorial, I will show you how to add padding to rows and columns in a table in LaTeX with multiple methods.
Add padding to rows in a table
In order to add extra vertical space in rows you can use \renewcommand{\arraystretch}{<factor>} or \def\arraystretch{<factor>} command before tabular. In both cases, the output will be similar. Take a look.
\documentclass{article}
\begin{document}
\section{Table with no extra vertical space}
\begin{table}[h]
\centering
\begin{tabular}{|c||c|c|c|c|c|}
\hline
x & 1 & 2 & 3 & 4 & 5 \\
\hline
f(x) & 1 & $\frac{1}{2}$ & $\frac{1}{3}$ & $\frac{1}{4}$ & $\frac{1}{5}$ \\
\hline
\end{tabular}
\caption{Table with extra vertical space}
\end{table}
\section{Table with extra vertical space}
\begin{table}[h]
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{|c||c|c|c|c|c|}
\hline
x & 1 & 2 & 3 & 4 & 5 \\
\hline
f(x) & 1 & $\frac{1}{2}$ & $\frac{1}{3}$ & $\frac{1}{4}$ & $\frac{1}{5}$ \\
\hline
\end{tabular}
\caption{Table with extra vertical space}
\end{table}
\section{Table with extra vertical space}
\begin{table}[h]
\def\arraystretch{1.5}
\centering
\begin{tabular}{|c||c|c|c|c|c|}
\hline
x & 1 & 2 & 3 & 4 & 5 \\
\hline
f(x) & 1 & $\frac{1}{2}$ & $\frac{1}{3}$ & $\frac{1}{4}$ & $\frac{1}{5}$ \\
\hline
\end{tabular}
\caption{Add extra vertical space with \textbackslash def\textbackslash arraystretch}
\end{table}
\end{document}Output:

Also, you can use \setlength{\extrarowheight}{<length>} and \\[<length>] provided by array package to add padding on rows. here,
\setlength{\extrarowheight}{<length>}: To add top padding.\\[<length>]: To add bottom padding.
\documentclass{article}
\usepackage{array}
\begin{document}
\section{Table with extra padding on top}
\begin{table}[h]
\centering
\setlength{\extrarowheight}{6pt}
\begin{tabular}{|c||c|c|c|c|c|}
\hline
x & 1 & 2 & 3 & 4 & 5 \\
\hline
f(x) & 1 & $\frac{1}{2}$ & $\frac{1}{3}$ & $\frac{1}{4}$ & $\frac{1}{5}$ \\
\hline
\end{tabular}
\caption{Table with extra padding on top}
\end{table}
\section{Table with extra padding on bottom on the last row}
\begin{table}[h]
\centering
\begin{tabular}{|c||c|c|c|c|c|}
\hline
x & 1 & 2 & 3 & 4 & 5 \\ % You can also add here [<len>]
\hline
f(x) & 1 & $\frac{1}{2}$ & $\frac{1}{3}$ & $\frac{1}{4}$ & $\frac{1}{5}$ \\[6pt]
\hline
\end{tabular}
\caption{Table with extra padding on bottom}
\end{table}
\section{Table with extra padding both top and bottom}
\begin{table}[h]
\setlength{\extrarowheight}{6pt}
\centering
\begin{tabular}{|c||c|c|c|c|c|}
\hline
x & 1 & 2 & 3 & 4 & 5 \\ % You can also add here [<len>]
\hline
f(x) & 1 & $\frac{1}{2}$ & $\frac{1}{3}$ & $\frac{1}{4}$ & $\frac{1}{5}$ \\[6pt]
\hline
\end{tabular}
\caption{Add extra padding both top and bottom}
\end{table}
\end{document}Output:

Add space between columns
In order to add horizontal space (padding) in the table or space between columns you can use the \setlength{\tabcolsep}{<value>} command to set the space. You have to add this command before tabular.
\documentclass{article}
\begin{document}
\section{Table with no extra padding}
\begin{table}[h]
\centering
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
A & B & C \\
\hline
D & E & F \\
\hline
\end{tabular}
\caption{Table with no extra padding}
\end{table}
\section{Table with extra padding on columns}
\begin{table}[h]
\setlength{\tabcolsep}{15pt}
\centering
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
A & B & C \\
\hline
D & E & F \\
\hline
\end{tabular}
\caption{Table with extra padding on columns}
\end{table}
\end{document}Output:

Add padding on a specific column
Situations arise while creating tables where we put different data in different columns. Now you can use the p{<length>} column specifier to increase the horizontal space of the specific column that contains the paragraph.
\documentclass{article}
\begin{document}
\section{Table with no extra padding}
\begin{table}[h]
\centering
\begin{tabular}{|c|c|c|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
A & B & This is a paragraph. This is a paragraph. This is a paragraph. \\
\hline
D & E & This is a paragraph. This is a paragraph. This is a paragraph. \\
\hline
\end{tabular}
\caption{Table with no extra padding}
\end{table}
\section{Table with extra padding on the last column}
\begin{table}[h]
\centering
\begin{tabular}{|c|c|p{3cm}|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline
A & B & This is a paragraph. This is a paragraph. This is a paragraph. \\
\hline
D & E & This is a paragraph. This is a paragraph. This is a paragraph. \\
\hline
\end{tabular}
\caption{Table with extra padding on the last column}
\end{table}
\end{document}Output:

Leave a Reply