# Table Limit: Sweave

I'm running into an issue. It seems that when I try to output more than 17 or 18 tables to a pdf document the remaining tables are ignored. When I split them across multiple Rnw files, there is no problem loading any of them.

It's not returning any errors, nor does the output of the first 17 or 18 tables seem to be anything other than expected.

• Windows 7 Pro
• Miketex 2.29
• RStudio (Using CompilePdf())
• R Version 2.14.1

I'm using the following packages:

\documentclass[12pt]{report}
\usepackage[landscape]{geometry}

% PREAMBLE

\usepackage{wallpaper}
\usepackage{fullpage}


Any ideas? Or things that I can double check?

-
You are probably specifying each table environment with the [h] option, which causes a well known problem: if TeX isn't able to place the first table, it delays it and all subsequent ones, running out of space after 18 tables. –  egreg Jan 29 '12 at 15:42
You might want to have a look at the ctan.org/pkg/morefloats package documentation (also at its "Alternatives" section). –  Stephen Jan 29 '12 at 16:55
I can think to \makeatletter\renewcommand{\table}[1][]{\@float{table}[!htp]}\makeatother that will make \begin{table} ignore an [h] optional argument and use [!htp] instead. –  egreg Jan 29 '12 at 16:56
@egreg: I did not mean to say "use morefloats" (would have posted an answer if I had wanted to say that), but "Read section 3 of its documentation (and the links given in that section) for more information about floats" (therefore the comment). But, yes, my comment could be misunderstood, sorry. Well, your comment and this comment should rectify this. –  Stephen Jan 29 '12 at 17:08
OK, but posted the whole section of the manual, because getting credit for "rtfm" seems strange (while sometimes one just would need to know which manual to read). –  Stephen Jan 30 '12 at 19:10

As others have pointed out, this is related to xtable() using the [ht] specification for table placement by default. This can be overridden, however. Rather than

xtable(...)


in your Sweave file, you can specify

print(xtable(...), table.placement="!htp")


or any other specification. I often use "H" from the float package

-
wow, that was hidden deep in ?print.xtable –  Brandon Bertelsen Jan 30 '12 at 21:10
Even so, I'm still confronted with the same issue. LaTeX Error: Too many unprocessed floats. –  Brandon Bertelsen Jan 30 '12 at 22:31
using [!htp] or [H]? –  Brian Diggs Jan 30 '12 at 22:36
using [!htp] I get the latex error. –  Brandon Bertelsen Jan 30 '12 at 23:00
I got it sorted. Using table.placement="!htp" worked after I found the unescaped %. –  Brandon Bertelsen Feb 1 '12 at 1:45

The problem seems to be in the fact that each table environment is passed the [h] option; if a table can be placed respecting this option (or the automatically provided [ht]), it and all subsequent tables will be queued and after other 17 tables LaTeX will hit the limit.

Enlarging the queue is not a suitable answer, because in that situation all tables will be printed at the end of the chapter.

The best strategy would be to modify how R produces the LaTeX code (which I don't know how); another possibility is to make LaTeX ignore the [h] option and provide a different set of options: for instance

\makeatletter
\renewcommand{\table}[1][]{\@float{table}[!htp]}
\makeatother


will pass the option [!htp] to all table environments (generated by R or not).

-
LaTeX Error: Too many unprocessed floats. Is what I get when I try to use this, is there anywhere that it should be placed? –  Brandon Bertelsen Jan 29 '12 at 18:02
Those three lines should go in the document preamble, before \begin{document} –  egreg Jan 29 '12 at 18:45
Confirmed, still receiving the same latex error, again around the 17th or 18th table. Manually (f/r) removing [ht] from each \table also results in the same error, there's about 86 tables that I'm trying to pdflatex (survey data) –  Brandon Bertelsen Jan 30 '12 at 17:31
It's quite strange; have you got also figure environments? –  egreg Jan 30 '12 at 17:42
@BrandonBertelsen A bogus document with my code and tables written as \begin{table}[h] gives no error. I loaded also the package you mention in the question. –  egreg Jan 30 '12 at 18:08

From the comment of the OP: "adding \clearpage to the end of every table removed the issue entirely". It is nice that it works, but it does not really solve the problem behind it. Therefore I cite the whole section of the morefloats package here as more general reference:

3 Alternatives (kind of)

If you really want to increase the number of (possible) floats, this is the right package. On the other hand, if you ran into trouble of Too many unprocessed floats, but would also accept less floats, there are some other possibilities:

• The command \clearpage forces LaTeX to output any floating objects that occurred before this command (and go to the next page).

• \cleardoublepage does the same but ensures that the next page with output is one with odd page number.

• Using different float specifiers: t top, b bottom, p page of floats.
• Suggesting LaTeX to put the object where it was placed: h (= here) float specifier.
• Telling LaTeX to please put the object where it was placed: h! (= here!) float specifier.
• Forcing LaTeX to put the object where it was placed and shut up: The float package provides the “style option here, giving floating environments a [H] option which means ‘PUT IT HERE’ (as opposed to the standard [h] option which means ‘You may put it here if you like’)” (float package documentation v1.3d as of 2001/11/08). Changing e.g. \begin{figure}[tbp]... to \begin{figure}[H]... forces the figure to be placed HERE instead of floating away. The float package, 2001/11/08 v1.3d, is available at CTAN: http://ctan.org/pkg/float
• The placeins package provides the command \FloatBarrier. Floats occurring before the \FloatBarrier are not allowed to float to a later place, and floats occurring after the \FloatBarrier are not allowed to float to a earlier place than the \FloatBarrier. (There can be more than one \FloatBarrier in a document.) The same package also provides an option to add to section headings automatically \FloatBarriers. It is further possible to make \FloatBarriers less strict (see that package’s documentation). The placeins package, 2005/04/18 v2.2, is available at CTAN: http://ctan.org/pkg/placeins

See also the following entries in the UK List of TeX Frequently Asked Questions on the Web:

and the excellent article on “How to influence the position of float environments like figure and table in LaTeX?” by Frank Mittelbach at http://tex.stackexchange.com/a/39020!

-
Mark the "and go to the next page" after the "\clearpage forces LaTeX to output any floating objects that occurred before this command". When that is OK for your document, it is OK, of course. –  Stephen Jan 30 '12 at 19:12
Agreed, it's not a perfect solution - but it's better than it not outputting at all. I've broken my tables into 17 outputs and then \clearpage –  Brandon Bertelsen Jan 30 '12 at 19:15