Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the correct way to center figures and tables (figure, table)?

\begin{center}
...
\end{center}

or

\begin{centering}
...
\end{centering}
share|improve this question
1  
Definitely never put the center environment around the figure environment! See Tables and sections get misplaced. (Not that I say Yiannis did this) –  Martin Scharrer Apr 11 '11 at 16:27
    
@MartinScharrer Definitely relevant that question but the answer only says don't do [X]. As such it's not as useful as lockstep's answer, which provides an explanation. –  Marc van Dongen Jun 22 '13 at 6:26

2 Answers 2

up vote 189 down vote accepted

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).

share|improve this answer
57  
Also note that \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 1 '10 at 10:56
16  
There's also the more esoteric \g@addto@macro\@floatboxreset\centering which, of course, should be preceded by \makeatletter and followed by \makeatother. –  egreg Apr 10 '11 at 14:25
    
Thanks for mentioning the 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 1:12
    
@Villemoes So why so many LaTeX editors use snippets for insert figures that use yet the center environment instead the centering declaration? –  Aradnix Sep 30 '14 at 3:09

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.

illustration of differences between <code>\centering</code> and <code>center</code> environment inside <code>figure</code> environments

\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.

Further comparisons

\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.