# Does \foreach \x in {1,2,3…} have a limit for the {1,2…} number of elements?

I have the following code which prints some images labelled by _{1,3,5...,37}.png. The following code works just fine.

\usepackage{tikz}
\foreach \x in {1,3,5,7,9,11,13,15,17,19,21,23,25}
{
\begin{figure}[h]
\begin{center}$\begin{array}{cc} \includegraphics[width=.99\textwidth,keepaspectratio]{./graficas/histograms/firstNeighboursDistribution_strength_0.0bosons_13window_\x.png} \end{array}$
\end{center}
\caption{First Neighbours Distribution}
\label{fig:histogram0.0}
\end{figure}
}


However, if I extend the \x range, let's say {1,3,5,7,9,11,13,15,17,19,21,23,25,27}, then I get a bunch of errors:

! LaTeX Error: Too many unprocessed floats.


Where's is the error?

• Something's up with your code: you don't use \x inside the loop. Also, can you make it a complete LaTeX document so that it can be compiled? I.e. start with \documentclass and end with \end{document}. Cheers. – John Wickerson May 29 '14 at 13:55
• break the loop into 2 loops and flush the unprocessed floats in between the two loops. – kiss my armpit May 29 '14 at 13:57
• – egreg May 29 '14 at 14:06
• As the message says: you have to many floats (figure environments) in a row. If the [h] indicates that you actually don't want them to float: Use minipages + \captionof instead. Why did you put your graphic in an array? – Ulrike Fischer May 29 '14 at 14:07
• This doesn't have anything to do with possible limitations of \foreach. The problem is that the images (floats) are being "collected" for typesetting until there is too many of them, perhaps because they're comparatively big in terms of the text block. Could you describe a little more about the actual image sizes? Also, inside the figure environment, just use \centering\includegraphics[..]{...}\caption{..}\label{..}, nothing more. – Werner May 29 '14 at 14:07

Using [h] makes the float almost impossible to place so makes running out of unprocessed float space almost inevitable. LaTex will have warned about each one and changed them to ht but htp is better.

But here you do not want the tables to float at all.

  \usepackage{float}

then use [H] which makes a non-floating table.
• @cacosomoza H makes the table environment into a minipage essentially, it never moves and it is immediately added to the page, so the pending float list that you filled is not used at all. Normally a table goes into a pending list and is added to the main document flow when latex finds a good spot, but h means not top of page, not bottom of page, not on a float page, so it is almost impossible to find a good spot so latex holds them back hoping to find a page that works when none will until you reach the end of document or fill the float queue – David Carlisle May 29 '14 at 14:55