Search code examples
latexpdflatex

Figures to flow/distribute automatically over pages in LateX


I have a long LaTeX script for making a document where most of the sections have three figures and they fit the page very good. In some random sections, we have six or nine figures. Therefore, the page will not fit these extra figures and they will overlay at the bottom of the page.

How can I automatically force the last three figures to appear on a separate page without the need to adjust each of these sections manually? (In other words, a way to make the clear page done automatically).

I am looking for something similar to longtable – Allow tables to flow over page boundaries environment to control the flow automatically.

Here is an example of the regular and random cases:

***Regular case***
    \begin{figure}[b!]
    \centering
     \includegraphics[width =\textwidth]{Path/A.png}
     \includegraphics[width =\textwidth]{Path/B.png}
     \includegraphics[width =\textwidth]{Path/C.png}
    \end{figure} 
    \clearpage

***Random case***
    \begin{figure}[b!]
    \centering
     \includegraphics[width =\textwidth]{Path/E.png}
     \includegraphics[width =\textwidth]{Path/F.png}
     \includegraphics[width =\textwidth]{Path/G.png}
     \includegraphics[width =\textwidth]{Path/H.png}
     \includegraphics[width =\textwidth]{Path/I.png}
     \includegraphics[width =\textwidth]{Path/J.png}
     \includegraphics[width =\textwidth]{Path/K.png}
     \includegraphics[width =\textwidth]{Path/L.png}
    \end{figure} 
    \clearpage

Solution

  • Thanks everyone for the feedback. I checked couple of posts on the internet regarding the issue and there are couple of ways to solve the problem (fairly good but not 100%).

    First Solution: As mentioned by @samcarter_is_at_topanswers.xyz , the figure environment does not support page breaks. \captionof (from the caption package) and \label can be used for figure captioning and referencing.

    \begingroup
         \centering
         \includegraphics[width =\textwidth]{Path/A.png} 
         \includegraphics[width =\textwidth]{Path/B.png} 
         \includegraphics[width =\textwidth]{Path/C.png} 
         \includegraphics[width =\textwidth]{Path/D.png} 
         \includegraphics[width =\textwidth]{Path/E.png} 
         \includegraphics[width =\textwidth]{Path/F.png} 
         \includegraphics[width =\textwidth]{Path/G.png} 
         \includegraphics[width =\textwidth]{Path/H.png} 
         \includegraphics[width =\textwidth]{Path/J.png} 
         \captionof{figure}{Whatever caption}
         \label{WhateverLabel}
    \endgroup 
    

    Second Solution (Not the best automated solution): Divide the figure into subfigure and use \ContinuedFloat to break the pages but with the same caption and label.

    \begin{figure}[b!]
    \centering
     \begin{subfigure}[b!]{\textwidth}
     \centering
     \includegraphics[width =\textwidth]{Path/A.png}
     \end{subfigure}
     \begin{subfigure}[b!]{\textwidth}
     \centering
     \includegraphics[width =\textwidth]{Path/B.png}
     \end{subfigure}
     \begin{subfigure}[b!]{\textwidth}
     \centering
     \includegraphics[width =\textwidth]{Path/C.png}
     \end{subfigure}
    \caption{whatever caption}
    \label{WhateverLabel}  
    \end{figure}
    \clearpage
    
    \begin{figure}[b!]
    \ContinuedFloat
     \begin{subfigure}[b!]{\textwidth}
     \centering
     \includegraphics[width =\textwidth]{Path/D.png}
     \end{subfigure}
     \begin{subfigure}[b!]{\textwidth}
     \centering
     \includegraphics[width =\textwidth]{Path/E.png}
     \end{subfigure}
     \begin{subfigure}[b!]{\textwidth}
     \centering
     \includegraphics[width =\textwidth]{Path/F.png}
     \end{subfigure} 
    \caption{whatever caption}
    \label{WhateverLabel} 
    \end{figure}
    \clearpage
    

    Reference of Second Solution: Subfigure in LaTeX – Full Guide

    Third Solution: Use figureSeries package created by @Prof. Thomas Weise. Unfortunately, it has not been updated since a while.

    References of Third Solution: figureSeries Package on GitHub and figureSeries Package on Stack Exchange