# Spurious whitespace in caption [duplicate]

Possible Duplicate:
Why the end-of-line % in macro definitions?

I am not sure what is happening with this MWE.

First the problem: You can clearly see the whitespace between the label and the text of the caption.

The MWE given below produces this behaviour.

\documentclass{report}

%--- SECTION1-----
%https://tex.stackexchange.com/questions/69662/how-to-globally-change-the-spacing-around-equations
\expandafter\def\expandafter\normalsize\expandafter{%
\normalsize
\setlength{\abovedisplayskip}{5pt plus 2pt minus 3pt}
\setlength{\abovedisplayshortskip}{3pt plus 2pt}
\setlength{\belowdisplayskip}{5pt plus 2pt minus 3pt}
\setlength{\belowdisplayshortskip}{3pt plus 2pt}
}

%-----SECTION2-----
\usepackage{setspace}

%-----SECTION3-----
\usepackage{caption}
\captionsetup{%
textfont={singlespacing},
}
%------------------
\begin{document}
\begin{figure}
\centering
\rule{3cm}{2cm}
\caption{Application of ICA for two sources with Gaussian distribution}
\end{figure}
\end{document}


The preamble is separated in three sections. The code in section-1 for setting various lengths is from how-to-globally-change-the-spacing-around-equations. As far as I understand it, the lengths will be defined each time \normalsize is defined/changed. Since we are setting these lengths to constants, the change in fontsize won't affect these lengths. Since various people have recommended this method, I am assuming this is a good practice.

Here are some observations:

1. If any one of the sections are commented out, then the white space disappears.
2. If section-1 is modified by adding comment mark % at the end of these lines then the whitespace disappears.
3. In fact, each line with setlength is adding a whitespace after the label in caption.
\expandafter\def\expandafter\normalsize\expandafter{%
\normalsize
\setlength{\abovedisplayskip}{5pt plus 2pt minus 3pt}%
\setlength{\abovedisplayshortskip}{3pt plus 2pt}%
\setlength{\belowdisplayskip}{5pt plus 2pt minus 3pt}%
\setlength{\belowdisplayshortskip}{3pt plus 2pt}%
}


The questions are:

1. Is the method of setting lengths correct?
2. Why does the spurious space disappear when setspace package is not used?
3. Why does the spurious space disappear when singlespacing option from package caption is not used?
4. Why does the spurious whitespace disappear when % is added at the end of the setlength command lines?

I would like to know what is happening here and what is the correct way of handling this problem.

• It is the end of line character. Search in this site for answers. For example Why the end-of-line % in macro definitions? and links provided in that question's comments. – user11232 Jan 1 '13 at 8:50
• @HarishKumar - in that case, the whitespace should still be there when package setspace is not used. – devendra Jan 1 '13 at 9:04
• A whitespace does not always make harm, e.g. it does make harm when TeX is in horizontal mode but does not make any harm when TeX is in vertical mode. If the caption option singlespacing is used and the setspace package is loaded, \setstretch{1} will be used prior typesetting the caption, and this will call \normalsize in TeXs horizontal mode. – user2574 Jan 1 '13 at 9:23
• Regarding Question 2: If the setspace package is not loaded the caption option textfont=singlespacing simply does nothing. (See caption3.sty how the font setting singlespacing is defined.) – user2574 Jan 1 '13 at 9:29
• @AxelSommerfeldt - This looks like an answer. So the moral of the story is that a whitespace left unattended might be dangerous in certain situations which might or might not arise depending on how/which packages are loaded. So to be on safe side, always remove whitespaces. Is there a way to make latex` give me errors whenever I have left an unintended whitespace? (something like strict compilation rules) – devendra Jan 1 '13 at 9:33