# What causes this large horizontal space between two sentences?

I have a large document based on the book documentclass with text and images, and sometimes I encounter a new sentence that has a huge space after a period. It looks like this:

I have attempted to make a MWE, but failed to get the problem.

This problem generally occurs when I have code that has this general structure:

A sentence that explains something shown in the images.
%
\begin{figure}[!ht]
\begin{minipage}[t]{0.48\textwidth}
\includegraphics[clip=true, trim=0 0 0 0, width=0.9\linewidth, angle=0]{image}
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\includegraphics[clip=true, trim=0 0 0 0, width=0.9\linewidth, angle=0]{image}
\end{minipage}
\end{figure}
%
\begin{figure}[htpb]
\includegraphics[clip=true, trim=0 0 0 0, width=0.8\linewidth, angle=0]{image}
\end{figure}
%
Another sentence that continues on the explanation.


It compiles then to something like this:

A sentence that explains something shown in the images.    Another sentence that continues on the explanation.
<image><image>
<image>


What could be causing this large jump? Is there some package/option that is known to give this discrepancy? As said I've tried to compile a MWE but failed to achieve this "error". If I knew what might cause this I could re-attempt to produce an MWE.

-
Add figure environments between paragraphs, not inside them. –  egreg Mar 20 '14 at 15:31
Change \end{figure} to \end{figure}% twice. There are spaces at the end of the lines. –  Malipivo Mar 20 '14 at 15:36
–  Werner Mar 20 '14 at 16:00
Not sure if it's a duplicate. It's the same subject/problem, but the linked question approaches it from the other side ("what does this solution do?") and my question is more along the lines of "I have this problem, how do I solve this". –  Bart Arondson Mar 20 '14 at 16:03
@Werner This is rather different from the canonical % at eol question. For a single figure you don't need the % and LaTeX explicitly checks for and compensates for any white space. It is just that its checks can not cope with a run of alternating insert and space nodes. –  David Carlisle Mar 20 '14 at 16:35

\end{figure}%%%%%%%%%%%%%%%%%<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Is it good practice to write \end{environment}% in general? Or is this something which I should consider per case? –  Bart Arondson Mar 20 '14 at 15:39