222

Often floats may land quite a bit later in the document than the point they are created, sometimes after a section break.

Is there a way to force a new section to start on a new page, after any unplaced floats?

1

4 Answers 4

245

Use the placeins package.

As noted in the comments, you can use

\usepackage[section]{placeins}

to automatically ensure floats do not go into the next section.

The package also gives you a \FloatBarrier command that you can use to prevent floats to appear beyond some point in your document. Use it as

% ... some floats here ...

\FloatBarrier

\subsection{My new subsection} 
6
  • 45
    Instead of putting manually \FloatBarrier before each new section you can just use section option of placeins package.
    – przemoc
    Commented Jul 4, 2011 at 11:14
  • 21
    @przemoc namely \usepackage[section]{placeins} Commented Aug 4, 2013 at 0:12
  • 11
    @przemoc Note, however, that this doesn't seem to work for subsections. Commented Jan 9, 2014 at 13:10
  • 2
    @FilipeCorreia, I added \begin{figure}[!h] to the figure and it also works for subsections that way.
    – M. Ali
    Commented Jan 30, 2017 at 11:46
  • 4
    However, the placeins package does not ensure that floats don't go into the previous section, i.e. a float with [t] may appear above the start of the section in which the float was specified.
    – Witiko
    Commented Nov 2, 2020 at 14:48
74

The command \clearpage will not only start a new page, but will also force any unset floats to be set before the page break. For documents with a left and a right page, \cleardoublepage does the same, but also ensures that the next non-blank page is a right hand page.

This is all independent of the section break, save that if you are using a class that does not put a page break before section breaks, this method will force them. But, from your question, this doesn't seem to be a problem in your case.

4
  • 1
    This has been driving me nuts for 3 months. THANK YOU!
    – PengOne
    Commented Aug 29, 2011 at 3:07
  • Simple. Full control. No extra packages needed. What else do you want?
    – luchonacho
    Commented Jan 29, 2016 at 16:53
  • 5
    This is not a good solution, since it requires clearing things every single time, instead of defining what one wants once and for the whole document. It clutters up the code a little bit. Commented Jan 6, 2017 at 14:25
  • When I place this command before a new section, figures from there appear above section name. Commented Sep 15, 2020 at 12:20
37

I'm now using:

\usepackage{placeins}

\let\Oldsection\section
\renewcommand{\section}{\FloatBarrier\Oldsection}

\let\Oldsubsection\subsection
\renewcommand{\subsection}{\FloatBarrier\Oldsubsection}

\let\Oldsubsubsection\subsubsection
\renewcommand{\subsubsection}{\FloatBarrier\Oldsubsubsection}

This is shamelessly plugged from the union of this and other answers on the topic, plus this. As I can't comment yet (silly requirement, that..), I'm sharing it with via a new answer instead.

Edit: Plus, for the sake of copy-pastability for others, I've incorporated egregs excellent correction to use the non-argumented version of section redefinition (before, the snippet above read \renewcommand{\section}[1]{\FloatBarrier\Oldsection{#1}} etc. - Thanks, egreg

1
  • 9
    Don't redefine \section with an argument: \renewcommand{\section}{\FloatBarrier\Oldsection} is sufficient and better, as it allows to still use \section*{title} and \section[Short]{Long title}. The same for \subsection and \subsubsection.
    – egreg
    Commented Mar 27, 2015 at 10:29
1

Code works well for all sections and subsections for me , package needs to be updated on miktex package library

\usepackage[section]{placeins}

\FloatBarrier

Above/Below every image or section

1
  • 13
    This doesn't add anything new to answer the question.
    – Werner
    Commented Apr 9, 2018 at 21:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .