center vs. \centering
Juni 13th, 2008 by Stefan Kottwitz
A frequently seen mistake is to use \begin{center} … \end{center} inside a figure or table environment. This center environment can cause additional vertical space. If you want to avoid that just use \centering instead like in this example:
\begin{figure}[ht] \centering \includegraphics{filename}% \caption{text}% \end{figure}
The additional space of the center environment is caused by a trivlist environment. Its defined by latex.ltx:
\def\center{\trivlist \centering\item\relax} \def\endcenter{\endtrivlist}
As you can see \center calls \centering too. By directly using \centering you could omit that trivlist.
Inside normal text \begin{center} … \end{center} is useful of course to center and to generate vertical space between the centered text and the surrounding text.
Concerning \centering it’s advisable to limit its scope by grouping. Inside a figure or table environment it’s already limited, but inside normal text you should use curly braces or \begingroup\centering … \endgroup:
{\centering Text
}As you can see I set an empty line before closing the centered group. If I do not end the paragraph by a paragraph break or the line by \\ then the following text outside the group will be centered too. \centering is also defined by latex.ltx:
\def\centering{% \let\\\@centercr \rightskip\@flushglue\leftskip\@flushglue \parindent\z@\parfillskip\z@skip}
It’s using \leftskip and \rightskip to flush left and right.
This topic was discussed in the LaTeX Community Forum, on mrunix.de and on ubuntuusers.de .
This entry was posted on Freitag, Juni 13th, 2008 at 07:05 and is filed under Layout. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.





September 10th, 2009 at 18:47
[…] be better than using begin{centre}. For those of you who are interested, here is an article on the centering vs. centre issue. My thanks go out to Stefan_T for his help! posted under […]
Dezember 11th, 2009 at 00:26
> … then the following text outside the group will be centered too.
Is this a bug? Why does it do this?
April 15th, 2012 at 16:35
@Yoo:
No, it’s just because \center is a switch: you switch on centered typesetting. Unless it’s turned off again (switched to left-aligned, say), LaTeX will continue centering. Everything’s fine there. The scope is a paragraph, as determined by the TeX engine.
Oktober 19th, 2012 at 17:13
how to end centering?
Oktober 23rd, 2012 at 00:28
[…] geplaatst door edraket doe es begin{center} en end{center} rond uw includegraphics? center vs. centering - TeXblog - Typography with TeX and LaTeX Voor de rest: begin{figure}[htb] centering includegraphics[width=0.9textwidth]{awesomeimage} […]
Mai 2nd, 2013 at 09:39
Just give it a scope {\centering …}