219

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?

lockstep
  • 250,273
Scott Morrison
  • 7,553
  • 6
  • 33
  • 32

4 Answers4

242

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} 
Rob Hyndman
  • 4,664
  • 4
  • 24
  • 23
72

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.

vanden
  • 30,891
  • 23
  • 67
  • 87
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

la_guentse
  • 501
  • 4
  • 5
  • 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 Mar 27 '15 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