Center a table in LaTeX (centering)
Write \centering at the start of the table environment. A tabular without a float goes into a center environment.
Center a table in a float
\centering applies to everything up to \end{table} and adds no vertical space.
\begin{table}
\centering
\begin{tabular}{lr}
\hline
Item & Price \\
\hline
Apple & 0.50 \\
\hline
\end{tabular}
\caption{Fruit prices}
\end{table}Center a table without a float
The center environment starts a new paragraph, centers its content and leaves space above and below.
Text before the table.
\begin{center}
\begin{tabular}{lr}
\hline
Item & Price \\
\hline
Apple & 0.50 \\
\hline
\end{tabular}
\end{center}
Text after the table.Center a table that is wider than the text
\centering cannot center a table that is wider than the text block; the table starts at the left margin and sticks out on the right. \makebox[\textwidth]{...} builds a box as wide as the text block and centers its content, so the table sticks out by the same amount on both sides.
\begin{table}
\makebox[\textwidth]{%
\begin{tabular}{|p{0.35\textwidth}|p{0.35\textwidth}|p{0.35\textwidth}|}
\hline
First column & Second column & Third column \\
\hline
\end{tabular}}
\caption{A table that is wider than the text block}
\end{table}Pitfalls
- Inside a
tableenvironment use\centering, notcenter: the environment adds its own space above and below to the space of the float. - A
longtableis centered without any command.\begin{longtable}[l]{...}moves it to the left margin.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- How-to Create a table in LaTeX
- How-to Fit a table that is too wide in LaTeX
- How-to Center an image in LaTeX
- How-to Center, left-align and right-align text in LaTeX
- Package
longtable