# Treat floatbarriers like page borders?

When I use the figure environment I like using [bt] options. I now have subsections acting as floatbarriers (using the extraplaceins package), and [b] / [t] does not work due to my restraining subsections. If I force it with [!t] or [!b] it does work, but will push the barrier (connected subsection) onto the previous/next page. Though correct I suppose, this is not what I'd like it to do.

Ideally it should treat subsections(floatbarriers) as page border, meaning e.g. [b] would put my figure at the end of its subsection--if it is sharing a page with a new subsection. Is this behaviour easy to implement?

\documentclass[10pt]{article}
\usepackage[section]{extraplaceins}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[demo]{graphicx}
\usepackage{color}

\begin{document}

\section*{Section ONE}
\blindtext
\begin{figure}[h]
\includegraphics[width=0.4\textwidth,height=2cm]{myimg.png}
\caption{\color{red} In next example I move this figure to the bottom of \underline{this section} with the [b] option}
\end{figure}
\blindtext

\section*{Section TWO}
\blindtext

\clearpage

%
{\color{red} Second illustration : Undesired effect of [b]}
\section*{Section ONE}
\blindtext
\begin{figure}[b]
\includegraphics[width=0.4\textwidth,height=2cm]{myimg.png}
\caption{\color{red} All that whitespace! [b] pushes section into next page instead of just placing float at bottom of section. How to change behaviour?}
\end{figure}
\blindtext

\section*{Section TWO}
\blindtext

\end{document}

• Can you include a MWE which shows a problem example and then explain what you would like it to look like. Jan 19 '14 at 12:58
• In other words: I want an option that moves my float to the bottom of the page, OR the bottom of the section--whichever comes first. This means I won't end up pushing my section headers onto new pages all the time (and creating loads of whitespace). Jan 19 '14 at 14:25

I couldn't find the extraplaceins package on CTAN, but assuming it is similar to the placeins package you can get pretty close to the desired behaviour with the help of the afterpage package and a little patching of the \@fb@secFB macro. I am doing this with the xpatch package. I believe this gives the desired behaviour for your MWE. For the more difficult case where the float is large and does not fit on the bottom of the page in the current section, but there is a lot of left over room the float can occur on a page after the next section has begun. It is not clear what you want to happen in this case.

\documentclass[10pt]{article}
% \usepackage[section]{extraplaceins}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[demo]{graphicx}
\usepackage{color}

\usepackage[section]{placeins}
\usepackage{afterpage}
\usepackage{xpatch}
\makeatletter
\AtBeginDocument{\xpatchcmd{\@fb@secFB}{\FloatBarrier}{\afterpage{\FloatBarrier}}{}{}}
\makeatother

\begin{document}

\section*{Section ONE}
\blindtext
\begin{figure}[h]
\includegraphics[width=0.4\textwidth,height=2cm]{myimg.png}
\caption{\color{red} In next example I move this figure to the bottom of \underline{this section} with the [b] option}
\end{figure}
\blindtext

\section*{Section TWO}
\blindtext

\clearpage

%
{\color{red} Second illustration : Undesired effect of [b]}
\section*{Section ONE}
\blindtext
\begin{figure}[b]
\includegraphics[width=0.4\textwidth,height=2cm]{myimg.png}
\caption{\color{red} All that whitespace! [b] pushes section into next page instead of just placing float at bottom of section. How to change behaviour?}
\end{figure}
\blindtext

\section*{Section TWO}
\blindtext

\clearpage

%
\section*{Section ONE}
\blindtext
\begin{figure}[h]
\includegraphics[width=0.4\textwidth,height=10cm]{myimg.png}
\caption{\color{red} In next example I move this figure to the bottom of \underline{this section} with the [b] option}
\end{figure}
\blindtext

\section*{Section TWO}
\blindtext

\clearpage

%
{\color{red} Second illustration : Undesired effect of [b]}
\section*{Section ONE}
\blindtext
\begin{figure}[b]
\includegraphics[width=0.4\textwidth,height=10cm]{myimg.png}
\caption{\color{red} All that whitespace! [b] pushes section into next page instead of just placing float at bottom of section. How to change behaviour?}
\end{figure}
\blindtext

\section*{Section TWO}
\blindtext

\end{document}