4

I am using \usepackage[section,above,below]{placeins} which does exactly what I want. In order to avoid too many blank pages, I am looking for a command that disables the \FloatBarrier at the following \section beginning. Is this possible?

Consider this example to illustrate the problem:

\documentclass{book}
\usepackage[section,above,below]{placeins}
\usepackage{graphicx}
\begin{document}
    \chapter{Only chapter}
    This very short introduction leaves most of the page empty...
% ---- HERE, A PAGE BREAK OCCURS ----
    \begin{figure}
        \includegraphics[width=\textwidth,height=8cm]{example-image-a}
        \caption{heading}\label{key}
    \end{figure}
    \section{My section}
    This page break is annoying!
\end{document}
  • wouldn't it be simpler not to use the section option and just use floatbarrier if neeed? – David Carlisle Apr 10 '16 at 0:02
  • @DavidCarlisle: generally yes but in >90% of the cases I want a '\FloatBarrier ' which is why I came up with this question. – riddleculous Apr 10 '16 at 0:16
5

You can just save the original section command before placeins alters it:

\documentclass{book}
\let\origsection\section
\usepackage[section,above,below]{placeins}

\usepackage{graphicx}
\begin{document}
\show\section
    \chapter{Only chapter}
    This very short introduction leaves most of the page empty...
% ---- HERE, A PAGE BREAK OCCURS ----
    \begin{figure}
        \includegraphics[width=\textwidth,height=8cm]{example-image-a}
        \caption{heading}\label{key}
    \end{figure}
    \origsection{My section}
    This page break is annoying!
\end{document}
1

The section option of placeins basically turns \section into:

\FloatBarrier\section

David's solution aims at locally go back to the initial definition of \section.

Here is another approach. It locally disables \FloatBarrier's effect instead:

\let\saveFloatBarrier\FloatBarrier% save the original command
\let\FloatBarrier\relax% disable FloatBarrier's effect
\section{My section without float barrier}
\let\FloatBarrier\saveFloatBarrier% restore FloatBarrier's original definition.

I prefer this approach, since it doesn't fiddle with \section's definition, you continue to use the regular \section command (what makes syntactical highlighting and IDEs keep track of the sectioning), and all redefinitions are located where it as takes effect (i.e. close to the \section macro, and not in the preamble).
However, this approach is more verbose and less compact - especially if you intend to use is multiple times (where David's answer solves the problem once and for all).


\documentclass{book}
\usepackage[section,above,below]{placeins}
\usepackage{graphicx}
\begin{document}
    \chapter{Only chapter}
    This very short introduction leaves most of the page empty...
    \begin{figure}
        \includegraphics[width=\textwidth,height=8cm]{example-image-a}
        \caption{heading}\label{key}
    \end{figure}

\let\saveFloatBarrier\FloatBarrier
\let\FloatBarrier\relax
    \section{My section}
\let\FloatBarrier\saveFloatBarrier
    This page break is annoying!
\end{document}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.