Should I use center or centering for figures and tables?
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).
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}