Graphics, Figures & TablesExtra Spaces from Nowhere!

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Extra Spaces from Nowhere!

Post by cbkschroeder »

Hi!

Thanks for taking the time to read my posting.

I seem to have stumbled upon a rather interesting difficulty which happens regardless of whether or not I use the floats package. In a nutshell, it seems that when I have a train of a few floats, curious spaces appear in the text that I don't at all expect. To provide an example, imagine the following:

****

This is a sentence which describes the floats which are about to come.
\begin{figure}
blahblah...
\end{figure}
\begin{figure}
blahblah...
\end{figure}
\begin{figure}
blahblah...
\end{figure}
\begin{figure}
blahblah...
\end{figure}
This is a sentence which discusses the ramifications of the floats.

****

After latex'ing this, the floats go wherever they may, but what's really interesting is what happens between the text:

This is a sentence which describes the floats which are about to come.<whole bunch of spaces, say 5 or 6 inter-sentence spaces>This is a sentence which discusses the ramifications of the floats.

The number of spaces inserted here is a function of the number of floats in the train. This happens with the table environment, too. If you're tempted to think it's something related the "blahblah..." between the \begin and the \end, know that even if blahblah...=NULL (ie there's nothing between the \begin{figure} and the \end{figure}) the spaces still appear. Another piece of information: if it deems necessary, latex will split those spaces across a line making it look as though I've started a new paragraph. UGH!

This makes me sweat... in a not so good way. I'd love it if someone might be able to slide along some insight into this. I'm using MikTeX 2.7 on XP SP3.

Thanks again for your time!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Re: Extra Spaces from Nowhere!

Post by kaiserkarl13 »

TeX is interpreting all the commands you have as zero-length words. Put % signs at the end of every line in the figure, and these spaces will go away. (You actually don't need them after EVERY line, but without an example it's harder to say which ones are causing the problem.)
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Re: Extra Spaces from Nowhere!

Post by cbkschroeder »

Well, as usual, I'm indebted. Thanks for your response; your suggestion worked.

Now... I'd love to know *why*! It turns out that as long as I put the % after the \end{figure} or \end{table} command, I'm good. That this should happen just seems so *wrong* - but certainly only my ignorance is wrong!

Could you please post a line or two to explain why this is happening?

Thank you so much, again!

Christian
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Extra Spaces from Nowhere!

Post by daleif »

it is bad practice to place figures inside the text anyway, place the figures between paragraphs, then

(1) you don't end up with figures that have jut one line of text below them, and

(2) this problem goes away
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Extra Spaces from Nowhere!

Post by nlct »

cbkschroeder wrote:Now... I'd love to know *why*! It turns out that as long as I put the % after the \end{figure} or \end{table} command, I'm good. That this should happen just seems so *wrong* - but certainly only my ignorance is wrong!
End of line characters are treated as spaces. The % discards everything up to and including the end of line character, so the space gets discarded. Unwanted spaces are usually caused by line breaks.

Regards
Nicola Talbot
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Extra Spaces from Nowhere!

Post by daleif »

isn't the problem here that the float inserts a whatsit and there fore the spaces after the envionment is actually enterpreted?
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Extra Spaces from Nowhere!

Post by cbkschroeder »

daleif wrote:it is bad practice to place figures inside the text anyway, place the figures between paragraphs, then

(1) you don't end up with figures that have jut one line of text below them, and

(2) this problem goes away
I had no idea this was considered bad practice; is this universally so? I've always done things this way. It seems to get my floats to be where I want them, at least reasonably. I'm not so fussy to use a specific package to get floats exactly in a specific place.
nlct wrote: End of line characters are treated as spaces. The % discards everything up to and including the end of line character, so the space gets discarded. Unwanted spaces are usually caused by line breaks.
OK, but if that's the case, then why is there not just a single space? Usually in LaTeX when I put many spaces between two words in the source file, the outcome is a single inter-word space. Considering that there are several commands in the figure environment, why am I only getting one space per environment invocation, yet if I invoke the figure environment several times, I get several spaces?
daleif wrote:isn't the problem here that the float inserts a whatsit and there fore the spaces after the envionment is actually enterpreted?
I'm not sure exactly what this means. Could you flesh it out a little?

Thanks, as always, for everyone's time.
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Extra Spaces from Nowhere!

Post by nlct »

cbkschroeder wrote: OK, but if that's the case, then why is there not just a single space? Usually in LaTeX when I put many spaces between two words in the source file, the outcome is a single inter-word space. Considering that there are several commands in the figure environment, why am I only getting one space per environment invocation, yet if I invoke the figure environment several times, I get several spaces?
That's because they are not consecutive spaces as they are broken up by whatsits. For example, try the following:

Code: Select all

A {} {} {} {} B
compared with

Code: Select all

A     B
In the first, the spaces are interrupted (albeit by something that has zero width) so each space counts, whereas in the second, the spaces are uninterrupted and so only count as a single space.

The spaces within the figure environment are floated with the figure, so they don't affect the rest of the paragraph. Whereas the space after each figure environment is turned into a space in the paragraph.

Hope that helps.

Regards
Nicola Talbot
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Re: Extra Spaces from Nowhere!

Post by cbkschroeder »

Nicola,

Thank you; that helps a lot. Now it's clear to me!

Cheers,

Christian
Post Reply