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.

I have a centering environment inside a figure. In this environment, I have a text written in a footnotesize style. If I make a line break (\\) in the text, then the text is not centered correctly anymore.

Can anyone tell me why the text is not centered correctly?

Screenshot:

enter image description here

Code:

\begin{figure}[H]
    \noindent   
    \begin{centering}     
      \caption[HTTP-Polling]{HTTP-Polling}
      \label{fig:polling}
      \includegraphics[scale=0.5]{images/polling}       
      \par
      \footnotesize Quelle: Heise Zeitschriftenverlag, 06. März 2012\\http://www.heise.de/developer/imgs/06/6/7/6/2/3/3/Polling-61cb54a128001c08.png
    \end{centering}     
\end{figure}
share|improve this question
2  
\centering is not an environment, but a command. Use \centering instead of \begin{centering} and remove \end{centering}. –  egreg Mar 7 '13 at 15:25
    
Or you could use \begin{center} ... \end{center}, although this would introduce additional vertical spacing, which you can redefine by first setting, e.g., \topsep=0pt. –  benwilfut Mar 7 '13 at 16:20

1 Answer 1

As mentioned in a comment there exists a directive called \centering that turns on "centering" from now on until the end of the current group. Technically speaking any command can turned into an environment (whether it makes sense or not) by simply using the command name without backslash as the envioronment name. The begin/end of the environment form a group and the command is executed within its scope.

For directives that can make sense, e.g., \begin{itshape} ... \end{itshape} makes perfect sense and in some cases is preferable over {\itshape ...}. However, \begin{bftext}{...} ... \end{bftext} does not as the \bftextonly operates on its argument, so the body of the environment doesn't serve any purpose.

Now coming back to your code: if a directive like \centering is used as an environment it is important to understand what happens at the end of this environment: nothing other than a group is closed ie the scope ends. That means what you have coded is equivalent of {\centering ...} without a final \par. But \centering operates only when the paragraph end is sensed (a \\ is really doing a par break internally) and by the time the final \par is seen (which is inside \end{figure} the \end{centering} was executed and changed the setting from centering back to normal justified settings. To make things like \centering work many environments such as the floats or the \parbox etc contain implicit \parcommands at their end to ensure that the final paragraph is finished with its current setting prior to closing the current group. But here this comes too late.

Therefore to fix this you would need to include a \par or empty line before \end{centering} or just use \centering (which is the better approach here) with the scope being the whole figure environment.

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.