2

Background

Writing a manual using LyX. All tables, figures, and source listings are always referenced in the paragraph (or enumerated step) that immediately precedes them. The preamble to the manual includes \raggedbottom to prevent large vertical spaces between list items.

Problem

The problem can be seen here:

The heading "1.1 Hierarchies" (no orphaned headings allowed) and the reference to "Figure 1.1" should be at the top of Page 2, on the same page as the image.

LaTeX Code

The images are added to floats so that they can have captions and cross-references. The LyX documents contain the following commands:

\float_placement H

I have tried changing the commands to:

\float_placement !htbp

These affect figure placement, but do nothing for the cross-references.

LyX Code

This is the code that LyX generates:

\begin{figure}[H]
\includegraphics{drawings/directory-hierarchy-01}

\caption{\label{fig:Example-Directory-Organization}Recommended Directory Organization}

\end{figure}

Possible Solutions

  1. \begin{samepage} ... \end{samepage}
  2. \clearpage

The \clearpage option is possible when the manual is complete. The samepage environment needs tweaking.

Question

What needs to be added to the document preamble to force the first cross-reference to remain on the same page as the item that is being referenced?

Related

Dave Jarvis
  • 11,809
  • @Seamus: (1) How do you make captions and cross-references without a float, using LyX? (2) OpenOffice, Microsoft Word, and FrameMaker have a "keep with next" option that allows such behaviour (unfortunately, it requires manually setting every paragraph); I thought LaTeX would have similar. (3) This question is about keeping the tables/Figures on the same page, which is different than "close to". – Dave Jarvis Jan 22 '11 at 23:17
  • 2
    (1) Using the caption package. – Caramdir Jan 23 '11 at 04:01
  • @Caramdir: At this point, there are over 220 listings, figures, tables, and captions... all within floats. The entire document is ih LyX. Converting all those items to use the caption package seems like a rather large effort, and seems counter to the "LyX-way": http://wiki.lyx.org/LyX/Figures – Dave Jarvis Jan 24 '11 at 09:16
  • 1
    @Dave, also have a look at Force figure placement in text for a solution using the float package. If the answers there are still not good for you, please edit your question to indicate why. Otherwise this question should be closed as duplicate. – Juan A. Navarro Jan 24 '11 at 10:56
  • 1
    @Dave From the wiki you linked to: "How do I get LyX to put the figure exactly where I want it?

    Select Document→Settings.... In the Float Placement section, unset "Use Default Placement" and select "Top of Page", "Page of Floats", "Here, if possible" and "Ignore LaTeX rules". [...]

    If you really insist, you can also simply select "Here definitely". This will insert the figure by all means at the current place. Note, though, that chances are high that this leads to ugly unbalanced pages. Usually, LaTeX does a rather good job in float placement if you do not restrict it too much."

    – Seamus Jan 24 '11 at 12:36
  • @Seamus: (1) Initially, I let LaTeX place the floats, but it did a terrible job (for a technical manual). (2) I forced all images to be Here definitely. (3) I would prefer ugly, unbalanced pages (\raggedbottom) to enumerated lists with large inconsistent spaces between the items (which was the result when LaTeX placed the images where it deemed proper). (4) The results are shown in the question. – Dave Jarvis Jan 24 '11 at 18:24
  • @Juan: I changed the question to show that I am using the float package, as described in the link you provided. Thank you for that. – Dave Jarvis Jan 24 '11 at 18:27