33

I would like to place figures in my document in certain subsections. Normally I would achieve this with float using [H]. But this would mean, that the figures are at fixed points in my text and sometimes this just doesn't look good.

I already found this question: How do I ensure that figures appear in the section they're associated with?

How can I tell LaTeX use subsections as float barriers instead of sections.

2 Answers2

44

If \subsection implicitely calls \FloatBarrier, then also \section should do it:

\usepackage[section]{placeins}

The following adds the implicit \FloatBarrier to \subsection:

\makeatletter
\AtBeginDocument{%
  \expandafter\renewcommand\expandafter\subsection\expandafter{%
    \expandafter\@fb@secFB\subsection
  }%
}
\makeatother
Heiko Oberdiek
  • 271,626
24

The placeins package, with the section option, redefines \section. You might succeed with \usepackage{placeins} and

\makeatletter
\AtBeginDocument{%
  \expandafter\renewcommand\expandafter\subsection\expandafter
    {\expandafter\@fb@secFB\subsection}%
  \newcommand\@fb@secFB{\FloatBarrier
    \gdef\@fb@afterHHook{\@fb@topbarrier \gdef\@fb@afterHHook{}}}%
  \g@addto@macro\@afterheading{\@fb@afterHHook}%
  \gdef\@fb@afterHHook{}%
}
\makeatother

This will do the same the section option does, but for \subsection instead of \section.

Untested. On a side note, don't use [H]: it's a sure cause for problems in placing floats.

egreg
  • 1,121,712