31

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[caption=false]{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!

5
  • This is the sort of thing that LaTeX typically isn't very good at, although in principle it shouldn't be that hard. (Also imagine automatically switching from a floating table to a longtable.) No solution from me at the moment (I'm marking assignments) but I'm interested to see what turns up. Feb 14, 2011 at 13:56
  • 2
    I guess the simplest way is to use separate figures, not subfigures. And you can modify the headers/footers, and the figure number output.
    – Leo Liu
    Feb 14, 2011 at 13:59
  • Shouldn't both "split" examples have a caption? The answers are assuming the first caption isn't necessary, which makes the whole problem much easier :) Feb 14, 2011 at 14:29
  • Thanks for the innput folks. Now, without wanting to break compatibility with loaded packages, I managed to produce a working solution. I digged into the graphicx manual and found that code\includegraphic[width=0.3\textwidth,height=0.2\textheight,keepaspectratio=true]{graphic.png}code would basically create a virtual grid of 3x5 rows & cols in which the images would be placed. When the page fills up, my program inserts a code\end{figure}\begin{figure}\ContinuedFloatcode and continues writing out the subfloats. However, this isn't a true multi-page self-breaking figure env, is it?
    – achennu
    Feb 14, 2011 at 17:31
  • Welcome to tex.sx! A tip: you can use backticks ` to mark your inline code as I did in my edit. Feb 14, 2011 at 18:12

3 Answers 3

6

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.

3
  • I hadn't thought of using the framed package here. It's probably the best option if you're not going to go the floating route. Feb 14, 2011 at 14:29
  • 1
    @vafa-khalighi I like this idea. The result ought to be to produce a 'mode' so that the user keeps supplying images, and latex keeps placing it in subfigures -- and beautifully, like latex is good at. That would be in keeping with the what-you-see-is-what-you-mean modality -- and rather usable! Looking forward to your package. What is it called?
    – achennu
    Feb 14, 2011 at 17:35
  • 1
    This seems to hide all the captions when using the subcaption package. Apr 27, 2020 at 13:46
3

I know that this is an old thread, but I recently created the package figureSeries which may be a good answer here, you can find it at http://github.com/thomasWeise/figureSeries.

The package figureSeries provides

  1. a facility to include an arbitrary number of (potentially differently-sized) sub-figures into a figure*-like construct,
  2. the ability to make this figure*-like construct look as if it was a floating object, which
  3. works well in both single-column and double-column documents.
3

do not use floats, it makes it easier to allow linebreaks. Here is an example which uses only the small package capt-of, which only defines one command and changes nothing in using floats. The counting of the subfloats can also be done by a subcounter, if you like.

\documentclass{article}
\usepackage[caption=false]{subfig} 
\usepackage[demo]{graphicx}
\usepackage{capt-of}

\newcommand\Image[3][]{%
  \tabular[b]{@{}c@{}}\includegraphics[#1]{#2}\\
    #3
  \endtabular}
\begin{document}

\Image[width=0.3\linewidth]{first}{a) First} \,
\Image[width=0.3\linewidth]{second}{b) Second} \,
\Image[width=0.3\linewidth]{third}{c) Third}

\Image[width=0.3\linewidth]{forth}{d) Forth} \,
\Image[width=0.3\linewidth]{fifth}{e) Fifth} \,
\Image[width=0.3\linewidth]{sixth}{f) Sixth}
\captionof{figure}{All of my six subfigures}

\end{document} 
2
  • Thanks for your answer. This does produce an 'array' of images, but it has a few problems. The user should not be producing the (sub)captions, latex should. Not producing subfigures takes away all the features of (sub)referencing, caption formatting and justification that subfig offers. While a low-key option, I guess this is not a good enough replacement. Also, I ran the code (replaced \linewidth by \textwidth) but still could not span the whole page. I'm not sure I understand the "{@{}c@{}}" in \tabular.
    – achennu
    Feb 14, 2011 at 17:46
  • It is an example of how it can be. And everything can be done by LaTeX, as I already pointed out.
    – user2478
    Feb 14, 2011 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .