tags:

views:

6817

answers:

5

I am using LaTeX and the figure environment.

I am well familiar with the parameters to that environment: [htbp], and I am also generally familiar with the strategies that LaTeX takes, by default, to decide where to put each figure. For example, by placing figures at the top or bottom of the page.

What I am wondering is whether there is a package, macro, or some commands that I can give so that if I have a single-column document and I mostly have a single in-text reference to a figure, that the figure would be more likely to be placed in the same page of the reference?

For example, imagine that I have a long paragraph which in the middle has a \ref{FIG:X}. When rendered, some of the paragraph appears before the page break, and some appears after the page break. I can also place the figure command somewhere before and after the whole paragraph. Is there a way to get it to actually be placed in the same page as the actual reference?

+2  A: 

I solve this problem by always using the [h] option on floats (such as figures) so that they (mostly) go where I place them. Then when I look at the final draft, I adjust the location of the float by moving it in the LaTeX source. Usually that means moving it around the paragraph where it is referenced. Sometimes I need to add a page break at an appropriate spot.

I've found that the default placement of floats is reasonable in LaTeX, but manual adjustments are almost always needed to get things like this just right. (And sometimes it isn't possible for everything to be perfect when there are lots of floats and footnotes.)

The manual for the memoir class has some good information about how LaTeX places floats and some advice for manipulating the algorithm.

Jon Ericson
The problem with [h] is that it often ignored, and that it does not take context (such as reference) location into account. I often end up in a situation where placing it either or after the paragraph alwyas ends up putting it not in the same line as the reference...
Uri
True. I tend to fiddle quite a bit with the final draft (and often earlier) to get tables and figures where I want them. So I'm not a huge fan of the automatic placement algorithm and [h] is the best way I know to avoid it moving things around. I don't tend to have large documents, however.
Jon Ericson
Heartily endorse your mention of 'memoir'
Brent.Longborough
+4  A: 

I don't want to sound too negative, but there are occasions when what you want is almost impossible without a lot of "artificial" tuning of page breaks.

If the callout falls naturally near the bottom of a page, and the figure falls on the following page, moving the figure back one page will probably displace the callout forward.

I would recommend (as far as possible, and depending on the exact size of the figures):

  • Place the figures with [t] (or [h] if you must)
  • Place the figures as near as possible to the "right" place (differs for [t] and [h])
  • Include the figures from separate files with \input, which will make them much easier to move around when you're doing the final tuning

In my experience, this is a big eater-up of non-available time (:-)


In reply to Jon's comment, I think this is an inherently difficult problem, because the LaTeX guys are no slouches. You may like to read Frank Mittelbach's paper.

Brent.Longborough
I agree. Hence I am wondering if there is a way to do this automatically. If I wanted to manually tinker with how my paper is formatted and get horrible results, I'd use Word :)
Uri
Good to know we aren't alone. On the other hand, I can't decide if this is an inherently difficult problem or if the float algorithm is poorly designed. My guess is the later. :-(
Jon Ericson
@Uri: Yes. I'm not really proposing tinkering, though; just a final pass when the document is ready to publish to tune up the relative positions of figures and callouts. You can do this with LaTeX and expect good results, while Word will break you.
Brent.Longborough
@Brent.Longborough: I withdraw my disparaging remark. ;-)
Jon Ericson
@Jon: ~"disparaging" - don't be too hard on yourself. In a world where 99% of stuff is rubbish, it was a reasonable, though perhaps not fully informed, guess.
Brent.Longborough
A: 

You can always add the "!" into your float-options. This way, latex tries really hard to place the figure where you want it (I mostly use [h!tb]), stretching the normal rules of type-setting.

I have found another solution:
Use the float-package. This way you can place the figures where you want them to be.

Sven Lilienthal
A: 

I have some useful comments. Because I had similar problem with location of figures. I used package "wrapfig" that allows to make figures wrapped by text. Something like ... \usepackage{wrapfig} \usepackage{graphicx} ... \begin{wrapfigure}{r}{53pt} \includegraphics[width=53pt]{cone.pdf} \end{wrapfigure}

In options {r} means to put figure from right side. {l} can be use for left side.

A: 

One way I found that helps with this is to use \include{file_with_tex_figure_commands}

(not input)

Eduardo Leoni