2

I want to flush my float (after an obviously necessary pre-pagebreak, since otherwise the float would be printed there anyway) and continue the text right below this flushed float with no additional page break after the float. My question is, if I have done this correctly.

The problem:

\documentclass{article}

\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}

\lipsum[1-3]

\begin{figure}[h]
\includegraphics[width=\textwidth]{example-image-a}
\caption{I am a figure}
\end{figure}

\lipsum[2]

\end{document}

I was curious, if there exists something like \flush:

\documentclass{article}

\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}

\lipsum[1-3]

\begin{figure}[h]
\includegraphics[width=\textwidth]{example-image-a}
\caption{I am a figure}
\end{figure}

\flush %error

\lipsum[2]

\end{document}

My current solution:

\documentclass{article}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{float} %does this only affect the single figure with 'H'?

\begin{document}

\lipsum[1-3]

\begin{figure}[H] %is this the right way?
\includegraphics[width=\textwidth]{example-image-a}
\caption{I am a figure}
\end{figure}

%\clearpage %this is wrong

\lipsum[2]

\end{document}
user1
  • 2,196
  • In this context, what do you mean by the word "flush"? – Steven B. Segletes Apr 17 '19 at 15:10
  • As you are using [H] there is nothing to flush. – Ulrike Fischer Apr 17 '19 at 15:13
  • \lipsum[2] appears twice (first time part of 1-3. I presume you mean the 2nd instance? – Steven B. Segletes Apr 17 '19 at 15:14
  • As it currently stands, the figure does print before \lipsum[2]...just not on page 1. There is no room on page 1 for an H non-"float" of this size. – Steven B. Segletes Apr 17 '19 at 15:15
  • 1
    if you want the figure to be there, [H] could be okay, the alternative is the placeins package and its \FloatBarrier command. – Ulrike Fischer Apr 17 '19 at 15:17
  • I'm deleting my comments (including this one). See https://tex.meta.stackexchange.com/questions/1477/should-we-clean-up-obsolete-comments – user1 Apr 17 '19 at 15:28
  • if you want there to be text below the float why use the optional argument to explictly prevent top floats? (normally latex warns about [h] and changes it to [ht]) – David Carlisle Apr 17 '19 at 16:10
  • @DavidCarlisle using [ht] also results in \lipsum[2] being print on the first page, which I do not want (call in mind, that this is a MWE. \lipsum[2] actually is a new section) – user1 Apr 17 '19 at 16:18
  • better to use the flafter package than rely on latex's error recovery if you don't want floats to float to the top of the current page. – David Carlisle Apr 17 '19 at 16:26
  • Is there a documentation of flafter? Can't find one on CTAN – user1 Apr 17 '19 at 16:38
  • Here it sounds like flafter affects all floats but not a specific one – user1 Apr 17 '19 at 16:40
  • I think if you ensure the pending floats at that point use ! and include t or just [!h] which is converted to [!ht] at the next page, then you can use \newpage and all floats should be output as there are no constraints stopping them being output as top floats. – David Carlisle Apr 17 '19 at 17:55
  • actually previous comment doesn't quite work but may be the basis of a solution – David Carlisle Apr 17 '19 at 18:15

1 Answers1

1

The credit goes to Ulrike's comment and James's one respectively this answer.

(\afterpage{\clearpage} doesn't do what I want (as I tried))

\documentclass{article}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{placeins}

\begin{document}

\lipsum[1-3]

\begin{figure}[h]
\includegraphics[width=\textwidth]{example-image-a}
\caption{I am a figure\label{fig:one}}
\end{figure}

\FloatBarrier

\lipsum[2]

\end{document}
user1
  • 2,196
  • while this works in this case (as \FloatBarrier just did \newpage) in the usual case it does \clearpage and so will force a page break after the flushed floats. – David Carlisle Apr 17 '19 at 16:17
  • @DavidCarlisle I don't get your comment – user1 Apr 17 '19 at 16:19
  • 1
    In the code above you can replace \FloatBarrier by \newpage and get the same output. generally \newpage does not flush all pending floats it just got lucky here and this float is output. \FloatBarrier tries that first, then if (as usually happens) the pending floats have not been output, it does \clearpage which flushes the floats, forcing a page break afterwards. – David Carlisle Apr 17 '19 at 16:25
  • 1
    @DavidCarlisle ok, this is actually sad, as I would expect \FloatBarrier to flush all floats and then continue the following content/text on the same (last) page. This means, the only advantage of \FloatBarrier is that I don't have to chose myself between \newpage and \clearpage – user1 Apr 17 '19 at 16:37
  • floatbarrier is only a dozen lines of code: if no floats do nothing else try \newpage if still floats \clearpage fi fi – David Carlisle Apr 17 '19 at 17:34
  • to see what I mean, duplicate the figure so there are two pending floats, you will then see \clearpage in action. – David Carlisle Apr 17 '19 at 18:11
  • I already tried that – user1 Apr 17 '19 at 18:57
  • 1
    @DavidCarlisle you are correct, \FloatBarrier is creating a new page for me. Is there an alternative to clear the floats without running the risk of a \clearpage being used? – nicolejane33 May 26 '22 at 09:35
  • @nicolejane33 basically, no, but try fewerfloatpages package) – David Carlisle May 26 '22 at 10:25