Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sweave xtable: how to position tables between text?

I have a number of tables with text around them describing them. Something like this:

This table shows blah blah...

<<echo=FALSE, results=tex>>=
print(
    xtable(x,
        caption = "blah", label = "tab:four", table.placement = "tbp", caption.placement = "top")
  , size = "small", table.placement="ht")
@

This table shows blah blah...

<<echo=FALSE, results=tex>>=
print(
    xtable(x,
        caption = "blah", label = "tab:five", table.placement = "tbp", caption.placement = "top")
  , size = "small", table.placement="ht")
@

I want all my descriptive text to be in line with the tables so that they follow in the sequence that I am writing them. But around the end of a page, some tables move off onto the next page and the descriptive text is just free floating. Is there some particular table.placement command that will ensure that everything stays the way that it is written?

like image 800
griffin Avatar asked Jul 01 '10 14:07

griffin


3 Answers

The latex float package provides the float specifier H, which allows you to force tables and figures to be precisely in the location they occur in the latex code. For example:

\usepackage{float} 

...

<<echo=FALSE, results=tex>>=
print(xtable(x),table.placement="H")
@
like image 140
nullglob Avatar answered Oct 15 '22 15:10

nullglob


See here for the table placement. You could try "!h" to force the table to stay where you wan't.

like image 11
Matti Pastell Avatar answered Oct 15 '22 15:10

Matti Pastell


I find \clearpage after a float is sometimes useful.

like image 3
Jeromy Anglim Avatar answered Oct 15 '22 16:10

Jeromy Anglim