30

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.

  • My eyes keep wanting to pronounce placeins like proteins. :) – Kaz Jun 11 '13 at 20:29
19

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.

  • This solves my problem with the positioning, but it changes all my section/subsection numbering. – user31386 Jun 11 '13 at 13:00
  • @DaniWho Sorry, I missed doing a change. Fixed. The \section command should have been \subsection. – egreg Jun 11 '13 at 13:04
  • Note that this solution eliminates the \FloatBarrier in \section! It can happen that a float ends between a section title and its first subsection. To avoid this, you need to redefine both. – Luis Jul 29 '16 at 17:43
  • this can clearly be used also for subsubsection – Alessandro Cuttin Oct 10 '18 at 15:29
34

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
  • Don't you mean "If \section implicitely calls \FloatBarrier, then also \subsection should do it"? – StrawberryFieldsForever Nov 4 '17 at 21:01
  • 1
    @StrawberryFieldsForever No. – Heiko Oberdiek Nov 4 '17 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy