2

The resolution of this problem appears at the end of this post. First here is the puzzling symptom.

I am using the LaTeX book class on a long complex 400pp document. Some floats generated with the LaTeX \begin{figure} environment (no optional arguments) decide to float many pages beyond the point where they were invoked (other floats in between the bad ones appear OK). Figures can float past a \cleardoublepage, past a \part{}, past a \chapter{}. Some appear on the second page of the following chapter! In between, there are pages containing no floats, where the figure could plausibly have been placed. There are no warnings in the .log file, neither on the page where the figure environment was invoked, nor on the page where the float actually appears.

Resolution: My book also contains many \marginpar's. The problem was that in just one place I had accidentally embedded a \marginpar inside a \footnote. I knew this was not allowed, but I did not realize that it would break something inside LaTeX and, for hundreds of following pages, mess up placement of figure floats. Fixing this one line fixed everything.

Phil Nelson
  • 113
  • 1
  • 7
  • Well, the generic thing would be using the same algorithm as you use when constructing an MWE, comment piece by piece, till the reason is obvious. – Johannes_B Oct 19 '15 at 16:49
  • 1
    Maybe you have over-sized content of float. For star tra to reduce it (for example use example-image from graphicx package with \includegraphics[width=0.5\hsize]{example-image}). And addto float options [htbp]. And see you log file, there probably is some warning ... – Zarko Oct 19 '15 at 16:50
  • 1
  • Thanks, Zarko: The float in question is only about 1/5 of the page height, so it's not over-sized. Thanks Johannes_B: I just wondered if there were any known precedent for floats passing over a chapter, and past a \cleardoublepage, which I thought was impossible. Thanks Ulrich: I will look into page output tracing. – Phil Nelson Oct 19 '15 at 16:56
  • 2
    What warnings do you receive in your .log regarding the float placement? Without any concrete content to play with, I think this comment thread is going to grow long before the question is closed... – Werner Oct 19 '15 at 16:59
  • There are no warnings in the .log file, neither on the page where the figure environment was invoked, nor on the page where the float actually appears. If this is not a well-known pathology, then probably this thread should be closed until I have had a chance to follow up on the previous suggestions. – Phil Nelson Oct 19 '15 at 17:09
  • I have been commenting blank lines between a paragraph and a float that I want to appear immediately or soon after it. It has helped, but I'm not sure of the mechanics involved. – repurposer Oct 19 '15 at 17:11
  • The placeins package "[d]e­fines a \FloatBar­rier com­mand, be­yond which floats may not pass; use­ful, for ex­am­ple, to en­sure all floats for a sec­tion ap­pear be­fore the next \sec­tion com­mand." – Stephen Oct 19 '15 at 18:29
  • @Stephen internally \FloatBarrier uses \clearpage so if the OP has disabled \clearpage then probably this will not work either, – David Carlisle Oct 19 '15 at 18:40
  • what does \meaning\clearpage print in your document? – David Carlisle Oct 19 '15 at 18:40
  • @DavidCarlisle: You are right. I just thought that it might be helpful to know it and while \cleardoublepage did not help, maybe \clearpage (or \FloatBarrier including \clearpage) are unchanged and work. Thus your question for \meaning\clearpage (and \meaning\cleardoublepage) is indeed the next step to find out what is going on. – Stephen Oct 19 '15 at 18:46
  • OK, I tried this: \meaning\cleardoublepage\meaning\clearpage inserts the following into the document: macro:-¿“clearpage “thispagestyle –empty ̋“strut “vfill “eject macro:-¿“vfill “eject “relax Also, \show\cleardoublepage inserts the following into the log file:

    \cleardoublepage=macro:

    ->\clearpage \thispagestyle {empty}\strut \vfill \eject . And \show\clearpage inserts the following into the log file:

    \clearpage=macro:

    ->\vfill \eject \relax .

    – Phil Nelson Oct 19 '15 at 19:21
  • 4
    I'm voting to close this question as off-topic because the underlying error was not revealed in the body of the posting but, instead, only in a follow-up posting/answer by the OP. As such, the poaing is likely to be of very limited value to other users of this site. – Mico Oct 21 '15 at 00:30
  • Help me out, Mico: I posted an Answer with the underlying error explained. Is that not the right procedure? I will now put the explanation in the body of the original post. It does seem to me that this is a problem that could mystify others. – Phil Nelson Oct 22 '15 at 00:53
  • You should have edited the original posting to clarify what was going on. What's (still) posted above in no way indicates the actual problem, as witnessed by the two well-intentioned by futile attempts at answers David Carlisle and Manuel Kuehner provided based solely on the information you provided in the posting. Revealing the real source of the problem in an "answer" is not a substitute for stating the problem clearly. – Mico Oct 22 '15 at 01:12
  • OK, I have now stated the symptom that confused me followed by its resolution. Next time I'll know better how to post. – Phil Nelson Oct 22 '15 at 01:55

3 Answers3

1

The latex float placement algorithm does not penalise (or even measure) the number of pages a float is moved. If it does not fit on the current page then it will be placed in the earliest place that meets the constraints.

Unless \cleardoublepage has been redefined then a float will not go past that point, so it is not really possible to comment on the details of your float placement unless you can show some code.

David Carlisle
  • 757,742
1

You can use the float package and use \begin{figure}[H] to place a single figure exactly where you want.

Maybe that is a quick way of solving your problem.

1

The problem was that in just one place I had accidentally embedded a \marginpar inside a \footnote. I knew this was not allowed, but I did not realize that it would break something inside LaTeX and, for hundreds of following pages, mess up placement of figure floats.

Once I guessed that this might involve \marginpar, I identified the problem by following Johannes_B's advice: I added a line that redefined \marginpar to do nothing, then slowly moved that line forward in the book manuscript from the beginning until the problem began to appear. This localized the bad code until it became obvious, as Johannes_B said it would be. Thanks Johannes_B.

Phil Nelson
  • 113
  • 1
  • 7