[Tex/LaTex] LyX is leaving a big gap between paragraphs in the place where float (figure) should be

floatslyxspacing

I just want to ask about why is LyX leaving a big gap between paragraphs surrounding a figure?. Not all paragraphs, but only between those paragraphs where I inserted a float (figure). The figure is placed somewhere else and all I left with is a big gap!

My thesis contains a lot of graphs all of which are floats and I want the figure to appear after the paragraph where it was first mentioned. I don't need big white spaces around the figures or to place a figure alone in a separate page.

enter image description here

Here is what I have in the preamble

\usepackage{cite}
\usepackage[version=3]{mhchem}
\usepackage{setspace}
%\onehalfspacing
\usepackage[bindingoffset=0.5in,margin=1in]{geometry}
\usepackage{ifthen}
\usepackage{graphicx} 
\usepackage[section,above]{placeins}
\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesection}{1em}{}
%\usepackage{setlength}
%\setlength{\intextsep}{-1ex} % remove extra space above and below in-line float
\usepackage[belowskip=-10pt,aboveskip=0pt]{caption}
\raggedbottom % to kill the annoying HUGE whitespace between paragraphs

as you can see from the last line in the preamble, I have tried using \raggedbottom to sort out this as recommended in another forum, but had no success.

LyX file: Removed as it contains unpublished data.

Best Answer

(It is a little bit difficult to say for sure, but I think I know why this happens. At least partly.)

There are two problems relating to the paragraph settings of the paragraphs containing the floats that can produce additional whitespace.

1. Empty paragraphs

If you look at the LaTeX source of one of the figures you'll see something like

\noindent
\begin{figure}
...

The problem here is the \noindent which comes from the paragraph settings in LyX. What you should do is right click just outside each figure, choose Paragraph settings, and check the box for Indent paragraph. If you have the source view open you'll see that the \noindent disappears when you click OK/Apply.

2. Centred alignment

For two of the figures (second and third last in your example) the alignment of the paragraph with the figure is set to Center, and if you look in the code you see something like

\begin{center}
\begin{figure}
...
\end{figure}
\par\end{center}

The surrounding center environment should be removed, by setting the paragraph alignment to Paragraphs default (justified).

So, why?

To demonstrate how this can give extra whitespace, consider the following LaTeX code, the output is shown below it:

\documentclass{article}
\begin{document}
Some words.

\noindent

More words.

\noindent \begin{figure}
This is a figure.
\end{figure}

Words

\begin{center}
\begin{figure}
Another figure
\end{figure}
\end{center}

More.
\end{document}

enter image description here

One or more empty line(s) signifies that a new paragraph should start, and new paragraphs are by default indicated by indentation. \noindent lets you remove this indentation for a single paragraph.

Now in the code above, the first \noindent does nothing, because there isn't anything there that can start a new paragraph. So you see that there is no extra space between Some words and More words. In the second case however, the \begin{figure} causes a new paragraph to start, but the only thing in it -- the figure itself -- floats away, so you're left with an empty paragraph.

Further, the center environment adds some verticl whitespace before and after, and when the only thing inside it is a figure that floats away, you're left with just that vertical whitespace.

Related Question