2

I am using the placins package with the section option. I noticed there seems to be a page break before a section. Below is my code. How do I bring the second section to the previous page?

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[section]{placeins}
\begin{document}
\section{First}
\lipsum[1-3]
\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}
\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}
\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}

\section{Second}
\lipsum[4]
\begin{figure}[htb]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}

\end{document}
  • 1
    that's exactly what \FloatBarrier does it forces a \clearpage page break to flush any floats if there are floats in the queue. – David Carlisle Oct 13 '15 at 22:17
  • 1
    by using [htb] you are preventing float pages (as you have not included p) which makes it much more likely that floats can not be positioned until flushed with \clearpage/\FloatBarrier – David Carlisle Oct 13 '15 at 22:18
5

This?

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{lipsum}
%\usepackage[section]{placeins}
\begin{document}
\section{First}
\lipsum[1-3]
\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}
\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}

\clearpage

\begin{figure}[ht]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}


\section{Second}
\lipsum[4]
\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.8\textwidth]{example-image} 
  \caption{\label{fig:} }
\end{figure}

\end{document}
  • That's a very nice solution. But there might be many places like that for a long document. Is it possible to avoid page break of float barrier even if remaining floats can't fit on the current page? It looks ugly when a small image takes a whole page. – godblessfq Oct 14 '15 at 11:36
  • 1
    @godblessfq the_only_ thing Floatbarrier does is force a page break (or do nothing) depending if there are float at that point, asking if can not force a page break really can't have a positive answer. – David Carlisle Oct 14 '15 at 11:39
  • Can those pending float at the point of float barrier be forced to be non float? – godblessfq Oct 14 '15 at 11:59
  • @godblessfq it's all open source, anything's possible (but it would be a completely different implementation, but better would be for you to look to see why they are floating away, latex fits them according to the constraints set so if it thinks they don't fit, and you think they do, then you should change the constraints to match your expectations. – David Carlisle Oct 14 '15 at 12:32
  • 1
    The problem of your answer is that I need to change the location of the clearpage if there are additional floats inserted before that point. I have a document that even if I set all float to be !htpb there still are too many unprocessed floats without the float barrier. – godblessfq Oct 14 '15 at 13:23
3

Changing the placement specifier of figures from htb to htpb should solve the problem.

Here is the relevant source of placeins:

 \def\FloatBarrier{\par\begingroup \let\@elt\relax
 V\edef\@tempa{\write\m@ne{Package placeins Info: Float barrier, from
 V  input line \the\inputlineno, processed on page \thepage, lands on
 V  page \noexpand\thepage. }}\@tempa
  \edef\@tempa{\@fb@botlist\@deferlist\@dbldeferlist}%
  \ifx\@tempa\@empty V\PackageInfo{placeins}{No floats held,}%
  \else
     \ifx\@fltovf\relax % my indicator of recursion
        \if@firstcolumn V\PackageWarning{placeins}{Some floats are stuck,}%
          \clearpage 
        \else V\PackageInfo{placeins}{Eject a column and check again:}%
          \null\newpage\FloatBarrier 
        \fi
     \else V\PackageInfo{placeins}{Must dump some floats}%
        \newpage \let\@fltovf\relax V\PackageInfo{placeins}{Check again:}%
        \FloatBarrier % recurse once only
  \fi\fi \endgroup
  \@fb@topbarrier }
  • Your solution actually helped me. The one above, although it's an accepted answer, does not seem as practical. – SashaKolpakov Sep 3 '19 at 3:19

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.