[Tex/LaTex] Splitting subfigures across multiple pages — but programmatically!

page-breakingsubfloats

I am using the subfig package to make many subfloats in a figure environment. It works well, as long as you realize that it tracks the whitespaces within the float environment.

It also has an option to split figures over multiple pages using a \ContinuedFloat command. This means that once a number of subfigures fill up a page, then you end the figure and in a new page start a figure with this \ContinuedFloat command — and it resumes laying out the subfigures (preserving the counts, etc.)

Note that the usepackage command should be as described, and the caption and captcont package should not be loaded, as it causes undesired redefinitions and incompatibilities.

\usepackage{subfig}    % don't load caption or captcont

\begin{figure}
\subfloat[First]{\includegraphic{first} } \,
\subfloat[Second]{\includegraphic{second} } \,
\subfloat[Third]{\includegraphic{third} } \,
\end{figure}

Then to continue subfigures later (presumably, on a new page)

\begin{figure}
\ContinuedFloat
\subfloat[Fourth]{\includegraphic{fourth} } \,
\subfloat[Fifth]{\includegraphic{fifth} } \,
\subfloat[Sixth]{\includegraphic{sixth} } \,
\caption{All of my six subfigures}
\end{figure}

Nifty! But for this you have to know how big your subfigures are, or how many of them you have. I have potentially 30 or 40 or 100 subfigures that I would like to lay out in an array on a page, continuing over into the next page. Also based on the dataset, the aspect ratio of the images maybe different and some will have 5 images per row, and others maybe only 3. These are basically the results from data analysis of some images, and I am producing the tex file programmatically.

Main question: Is there a way to detect that after N subfigures the page is full, and to continue the remaining subfigures in a new page?

Or any other suggestions on how to deal with this issue are also welcome!

Best Answer

Why not redefine the figure environment so that your figure environment can be multi-page and accept captions. This of course ignores the t, b, h options:

\renewenvironment{figure}[1][]{%
  \def\@captype{figure}%
  \par\nobreak\begin{center}\nobreak}
  {\par\nobreak\end{center}}

I am actually writing a package that redefines float from LaTeX and uses some of the code offered by the framed package so that a floating environment such as table or figure can be more than a page. I should be able to upload it to CTAN by the end of the weak.