center vs. centering
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.
Pingback: oconnoat.com » Blog Archive » Automatic Table Row Numbers in LaTeX
Pingback: ATTN: Studenten steun- en klaagthread - Deel 22 - Pagina 117 - 9lives - Games Forum