Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
    
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. –  Will Robertson Feb 14 '11 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 '11 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 :) –  Will Robertson Feb 14 '11 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? –  arjmage Feb 14 '11 at 17:31
    
Welcome to tex.sx! A tip: you can use backticks ` to mark your inline code as I did in my edit. –  Hendrik Vogt Feb 14 '11 at 18:12

2 Answers 2

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} 
share|improve this answer
    
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. –  arjmage Feb 14 '11 at 17:46
    
It is an example of how it can be. And everything can be done by LaTeX, as I already pointed out. –  Herbert Feb 14 '11 at 18:05

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.

share|improve this answer
    
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. –  Will Robertson Feb 14 '11 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? –  arjmage Feb 14 '11 at 17:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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