What is the correct way to center figures and tables (figure, table)?
\begin{center}
...
\end{center}
or
\begin{centering}
...
\end{centering}
What is the correct way to center figures and tables (figure, table)?
\begin{center}
...
\end{center}
or
\begin{centering}
...
\end{centering}
The correct way is
\begin{figure}
\centering
... (Code for pictures, captions) ...
\end{figure}
\begin{center} ... \end{center} inside a figure environment will result in (generally unwanted) additional vertical space.
Note that while \centering produces proper spacing, manually adding this command to every figure environment (and to every table and custom-made float) is tedious and goes against the idea of separating the content of a document from the format. Even better ways are to add the following to your document preamble (thanks to egreg for the tip):
\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother
or to load the floatrow package which allows to control the justification of float contents from the preamble (with objectset=centering as default).
\centering is a declaration, not an environment. That \begin{centering} works is an unfortunate consequence of the way environments work internally in LaTeX: The environment foo essentially consist of two macros \foo and \endfoo which are called by \begin{foo} and \end{foo}, respectively (along with some error checking, such as proper nesting). But since \endfoo is called via \csname endfoo\endcsname, that macro doesn't actually have to exist. This means that even stuff such as $\begin{alpha}\end{alpha}$ works (but should of course not be used).
– Villemoes
Dec 01 '10 at 10:56
\g@addto@macro\@floatboxreset\centering which, of course, should be preceded by \makeatletter and followed by \makeatother.
– egreg
Apr 10 '11 at 14:25
floatrow package which looks very, very powerful (I should have found that before, now changing all figure/table definitions in my thesis will be quite some work).
However, the documentation is so long and there are so many possibilities of configuration, that it will be very hard to figure out the best setup.. is there a tuturial with a "recommended" setup for a twopage thesis? :-(
– MostlyHarmless Apr 11 '11 at 01:12center environment instead the centering declaration?
– Aradnix
Sep 30 '14 at 03:09
IEEEtran, \g@addto@macro\@floatboxreset\centering is ineffective since \figure redefines \@floatboxreset. I use etoolbox and \patchcmd{\figure}{\normalsize}{\normalsize\centering}{}{}.
– bers
Jan 15 '16 at 14:42
\documentclass[onecolumn]{IEEEtran}\usepackage{etoolbox}\patchcmd{\figure}{\normalsize}{\normalsize\centering}{}{}\begin{document}\begin{figure}Test\end{figure}\end{document} is working fine for me. No errors, and "Test" is centered.
– bers
Nov 10 '21 at 11:59
This is a (very late!) supplement to lockstep's answer which just offers a visual demonstration of the difference between the use of \centering and the center environment within figure environments.
Each page shows 2 figures, one using \centering and one using center. The differences in spacing are the result of ordering the two figure environments differently. On the first page, \centering is used first and the center environment second, while on the second page, this order is reversed.
The results clearly show inappropriate spacing for the lower figure (first page) and the upper figure (second page) i.e. for whichever figure uses center rather than \centering.
showframe is used to show the overall page layout.

\documentclass{article}
\usepackage{graphicx,showframe,kantlipsum}
\begin{document}
\kant[1]
\begin{figure}
\centering
\includegraphics[scale=.25]{example-image-a}
\caption{Figure with centering}
\end{figure}
\kant[2]
\begin{figure}
\begin{center}
\includegraphics[scale=.25]{example-image-a}
\end{center}
\caption{Figure in center environment}
\end{figure}
\kant[3]
\begin{figure}
\begin{center}
\includegraphics[scale=.25]{example-image-a}
\end{center}
\caption{Figure in center environment}
\end{figure}
\kant[4]
\begin{figure}
\centering
\includegraphics[scale=.25]{example-image-a}
\caption{Figure with centering}
\end{figure}
\end{document}
Finally, compare two pages with two figures each. The first page includes figures which use \centering, while the second includes figures which use the center environment.

\documentclass{article}
\usepackage{graphicx,showframe,kantlipsum}
\begin{document}
\kant[1]
\begin{figure}
\centering
\includegraphics[scale=.25]{example-image-a}
\caption{Figure with centering}
\end{figure}
\kant[2]
\begin{figure}
\centering
\includegraphics[scale=.25]{example-image-a}
\caption{Figure with centering}
\end{figure}
\kant[3]
\begin{figure}
\begin{center}
\includegraphics[scale=.25]{example-image-a}
\end{center}
\caption{Figure in center environment}
\end{figure}
\kant[4]
\begin{figure}
\begin{center}
\includegraphics[scale=.25]{example-image-a}
\end{center}
\caption{Figure in center environment}
\end{figure}
\end{document}
Since this thread gave birth to a little misunderstanding, I would like to add a note.
As the other answers say, center environment should never be used within a figure or table environment, you should use \centering instead:
But if your table or image are not floating, that is you would like to have them exactly where you put them, i.e. they are not within a figure or a table environment, you can use a center environment without problems. It is equivalent to a table or a figure environment with the H option of float package.
If you would like to add a caption, you can use \captionof from \caption package.
\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=above}
\usepackage{float}
\begin{document}
You can use \texttt{center} environments here, because they are not within a floating one:
\begin{center}
\captionof{table}{A non-floating table within a \texttt{center} environment}
\begin{tabular}{cc}
\toprule
Ducks & Lions \\
\midrule
1 & 2 \\
\bottomrule
\end{tabular}
\end{center}
\begin{center}
\includegraphics[width=.5\linewidth]{example-image-a}
\captionof{figure}{A non-floating figure within a \texttt{center} environment}
\end{center}
They are equivalent to a \texttt{table} or \texttt{figure} environment with the \texttt{H} option of \texttt{float} package:
\begin{table}[H]
\centering
\caption{A non-floating table with \texttt{H} option}
\begin{tabular}{cc}
\toprule
Ducks & Lions \\
\midrule
1 & 2 \\
\bottomrule
\end{tabular}
\end{table}
\begin{figure}[H]
\centering
\includegraphics[width=.5\linewidth]{example-image-a} \caption{A non-floating figure with \texttt{H} option}
\end{figure}
Just to show the also the lists works:
\listoftables
\listoffigures
\end{document}
flushleft and flushright environments, as well as \raggedright and \raggedleft commands
– CarLaTeX
Sep 14 '19 at 20:06
centerenvironment around thefigureenvironment! See Tables and sections get misplaced. (Not that I say Yiannis did this) – Martin Scharrer Apr 11 '11 at 16:27