# LyX is leaving a big gap between paragraphs in the place where float (figure) should be

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.

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.

-
Welcome to TeX.SX! There isn't really enough information to answer your question. What position have you defined for the figure in the float settings? From your description you don't want it to float, so you should use Here definitely. To increase the chances of getting good answers it is generally best to add a minimal working example, see meta.tex.stackexchange.com/questions/4488/… (and meta.tex.stackexchange.com/questions/228/…). –  Torbjørn T. Aug 7 '14 at 15:54
@Torbjørn T., thanks for the reply. All my figures are set to by Here if possible and Ignore Latex reules. What really annoys me is the gap left between the paragraphs, not the positioning of the figures. (Although I would like to solve the problem of figures positioning, but will leave it for another discussion.) –  Abdulaziz Aug 7 '14 at 21:12
Perhaps your figures have invisible white space around them, i.e. their bounding box is not correct. In such a case, that you may test by putting them in an \fbox, is to crop them. –  Bernard Aug 7 '14 at 21:12
Well, I for one would need to see a sample .lyx file (or exported .tex), as mentioned above, to answer this, I am unable to guess at the cause. –  Torbjørn T. Aug 7 '14 at 21:30
@TorbjørnT., here you go. The .lyx file is now in the question. For all, please don't use what is written in the file. It's a part of my thesis. –  Abdulaziz Aug 7 '14 at 21:52

(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}

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.

-
thanks for the help. Unfortunately, it does not solve the problem. I have removed the indentation from all figures as you described and removed also from all the document, but the problem is still not solved. –  Abdulaziz Aug 8 '14 at 14:59
@Abdulaziz I updated my answer, having noticed an additional problem. –  Torbjørn T. Aug 8 '14 at 22:35

@Torbjørn T. Thank you very much. The problem has been solved.

For anyone facing the same problem, the steps are as follows:

1. Change the Document>Settings>Text Layout to Indentation: Default (Even if you still want to keep your document not-indented as I do)
2. This will be quite tedious! For all figures: inside the figure float, change the paragraph settings to be Justified and Indent Paragraph. Avoid using Center.
3. Now if you want your paragraphs to be separated by a skip rather than to indent them. Do so as described in step 1.

All credit goes to Torbjørn T.

N.B. I wish that there is a command that changes the paragraph settings for floats only rather than doing them manually one by one!

-
Regarding point 2: What you do inside the float doesn't really matter, it's what's outside that causes these problems. Regarding your N.B: The settings in Document --> Settings --> Text layout does not change the settings of individual paragraphs (i.e. it doesn't add \noindent everywhere). So I think you must have changed it into not indented and centred manually at some point, so it is just a matter of not doing that in the first place. Changing paragraph settings for float paragraphs doesn't really make sense anyway, as floats 1) float away and 2) aren't affected by them anyway. –  Torbjørn T. Aug 9 '14 at 7:49