3

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[linktoc=Section]{hyperref}
\usepackage{fullpage}

Any ideas? Or things that I can double check?

Alan Munn
  • 218,180
  • 2
    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
  • Right you are. Thanks for pointing that out. Any thoughts on a work around, xtable() from R uses this option as the default and I see no option of changing it (other than building my own, which I'd prefer not to do). – Brandon Bertelsen Jan 29 '12 at 16:51
  • 1
    You might want to have a look at the http://ctan.org/pkg/morefloats package documentation (also at its "Alternatives" section). – Stephen Jan 29 '12 at 16:55
  • 1
    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
  • @Stephen morefloats wouldn't solve the problem, as all the tables would be printed at the end of the chapter anyway. – egreg Jan 29 '12 at 16:58
  • 2
    @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
  • Just for clarification purposes, every table is assigned [ht] options automatically. – Brandon Bertelsen Jan 29 '12 at 17:58
  • Also, @Stephen adding \clearpage to the end of every table removed the issue entirely. If you put that as an answer, I'll accept it as your solution since it was the first paragraph of the document you suggested. – Brandon Bertelsen Jan 29 '12 at 18:45
  • 1
    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

3 Answers3

4

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).

egreg
  • 1,121,712
  • 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
  • I think it may be one of the packages that I'm using. When I remove all the preamble it outputs without issue (and without \clearpage) – Brandon Bertelsen Jan 30 '12 at 18:01
  • By process of elimination it seems like it's some kind of interaction with the hyperref package. Sad face. – Brandon Bertelsen Jan 30 '12 at 18:07
  • 1
    @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
  • xtable() (from R) outputs tables with [ht] set. Not sure if that makes a difference. Did your document have more than 18 tables? – Brandon Bertelsen Jan 30 '12 at 19:53
  • @BrandonBertelsen I've tried with 125. – egreg Jan 30 '12 at 20:28
  • What system / version are you using? – Brandon Bertelsen Jan 30 '12 at 22:32
  • @BrandonBertelsen TeX Live 2011, but it shouldn't make a difference. However I don't have R; anyway it shouldn't matter. – egreg Jan 30 '12 at 22:35
  • I'm sinking output directly to a "tex" file and then running pdflatex. So there's nothing special going on from that perspective. Now its not working even if I remove all the preamble. lol sigh. – Brandon Bertelsen Jan 30 '12 at 23:10
  • I found it. In the 85th table (fml), there was an errant % in the caption that was not escaped properly and this was causing the error. – Brandon Bertelsen Feb 01 '12 at 01:45
4

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 https://tex.stackexchange.com/a/39020!

David Carlisle
  • 757,742
Stephen
  • 14,890
  • 1
    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
2

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