# Vertical spacing in floats

I am using a float inside the text. As I found out, using \intextsep I could set space above and below the float and the texts. But when I am using \setlength{\intextsep}{5mm}, the space below the float is more than the one above it. Why they are not equal?

% Preview source code

%% Do not edit unless you really know what you are doing.
\documentclass[english]{report}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{graphicx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% A simple dot to overcome graphicx limitations
\newcommand{\lyxdot}{.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{setspace}
\setlength{\intextsep}{5mm}
\setlength{\belowcaptionskip}{0mm}

\setstretch{2}

\makeatother

\usepackage{babel}

\begin{document}
Text Text Text Text Text Text Text Text Text Text Text Text

\begin{figure}[h]
\begin{centering}
\includegraphics[scale=0.5]{\lyxdot \lyxdot /Pictures/fedora}
\par\end{centering}

\caption{}

\end{figure}
Text Text Text Text Text Text Text Text Text Text Text Text
\end{document}

-
I get equal space above and below a float if I use \setlength{\intextsep}{5mm}. Please edit your question to include a minimal working example (MWE) that shows the behaviour you describe. – Jake Oct 25 '11 at 2:44
Thanks for editing your question. Note that an MWE should be a complete document, starting from \documentclass, i.e. it should include your preamble. If I insert your code into a document, I get slightly more space above the float. Please turn your example into a complete document, so we can properly assess what's happening. – Jake Oct 25 '11 at 3:03
@Jake Thanks, and sorry again! I already added a working sample which produce same result for me! Hope you could help! I Just started learning LaTex. – amrzar Oct 25 '11 at 3:15

Here's an explanation of what's going on, using a step-wise approach. First of all, consider the following toned-down version of your example code:

\documentclass{report}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\setlength{\intextsep}{0mm}
\begin{document}
Line 1: Text Text Text Text Text Text Text Text Text Text Text Text

\begin{figure}[h]
\centering
\includegraphics[scale=0.5]{\lyxdot \lyxdot /Pictures/fedora}
%  \caption{This is a caption}
\end{figure}

Line 2: Text Text Text Text Text Text Text Text Text Text Text Text\par
Line 3: Text Text Text Text Text Text Text Text Text Text Text Text
\end{document}


All the packages have been removed and the code slightly modified (the centering environment has been changed to \centering that has a scope within the figure environment; numbered lines of Text Text...; demo package option to graphicx that allows anyone to compile the example and replace all images with a black rectangle; commented out the \caption command). This is what the output looks like.

Note how the baseline of Line 1 is "tight" to the figure. If you zoom in, you'll see that the text is literally touching the figure. This is because of \setlength{\intextsep}{0mm}. Why then is Line 2 not "tight" to the figure from the bottom? It actually is! In fact, the distance from the bottom of the figure to the baseline of Line 2 is exactly the same as the baseline skip from Line2 to Line 3. It may seem like it isn't "tight", but baseline to baseline (or the \baselineskip) it is.

This marginal difference is exaggerated when adding the other components of your original example, such as the setspace package and \setstretch{2} while still keeping \setlength{\intextsep}{0mm}:

However, the \baselineskip between the figure and Line 1 is still the same as the \baselineskip between Line 1 and Line 2, as expected. Adding a \caption further increases this gap visually:

However, as before, the \baselineskip from the bottom of the caption (the bottom of the g and p characters) is exactly the same as the \baselineskip from Line 1 to Line 2.

If you want to correct for this, you need to add the required skip to the top of the float, for example:

\documentclass{report}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\setlength{\intextsep}{0mm}
\begin{document}
Line 1: Text Text Text Text Text Text Text Text Text Text Text Text \par \kern 5pt

\begin{figure}[h]
\centering
\includegraphics[scale=0.5]{\lyxdot \lyxdot /Pictures/fedora}
\caption{This is a caption}
\end{figure}

Line 2: Text Text Text Text Text Text Text Text Text Text Text Text\par
Line 3: Text Text Text Text Text Text Text Text Text Text Text Text
\end{document}


Here 5pt seemed reasonable. Or, if you want to automate this, then you can use the etoolbox package:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\BeforeBeginEnvironment{figure}{\kern 5pt}%


Note though that this will place a 5pt gap between the figure and text even if your figure ends up at the top of the page. Such manual interaction is usually not good style, even if it may seem visually inaccurate. LaTeX will do a good enough job in terms of spacing.

Edit: As @Jake suggested, a much better approach would be to modify the skip below the caption (or \belowcaptionskip) to remove some of the overly visual \baselineskip. In the following example, an \intextsep of 5pt is set, with \belowcaptionskip set to -\baselineskip+1.6ex (to get rid of \baselineskip and add a "normal line" height; obtained via experimentation when \intextsep=0pt):

\documentclass{report}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{setspace}% http://ctan.org/pkg/setspace
\begin{document}
\setlength{\intextsep}{5pt}%
\setstretch{2}%
Line 1: Text Text Text Text Text Text Text Text Text Text Text Text

\begin{figure}[h]
\centering
\includegraphics[scale=0.5]{\lyxdot \lyxdot /Pictures/fedora}
\caption{This is a caption}
\end{figure}

Line 2: Text Text Text Text Text Text Text Text Text Text Text Text\par
Line 3: Text Text Text Text Text Text Text Text Text Text Text Text
\end{document}

-
Since the issue is aggravated by the OP's use of setstretch{2}, instead of adding white space at the top, I would have suggested "cancelling" the unwanted vertical space below the figure by setting \setlength{\belowcaptionskip}{-\baselineskip} \addtolength{\belowcaptionskip}{1.5ex} (i.e. reduce the space by a whole baselineskip, then add the space that a "normal" line of text would take up). This has the advantage of adapting to any changes of the setstretch parameter, and not requiring an external package. Can you see any issues with this approach? – Jake Oct 25 '11 at 4:52
@Jake: That's much better. Not sure about the look when a single line of text may end up below a figure [h] at the bottom of a page. However, this may be rare. Contextual rewording or perhaps a \needspace might solve this problem on a as-needed basis. – Werner Oct 25 '11 at 5:22
Really Helpful! Thanks – amrzar Oct 25 '11 at 5:52