1

Having read the docs I think this is unlikely, but decide to ask regardless.

I'm writing a poster, and the tabular has to stay within the center environment instead of table environment. (The table environment is a float, which does not work within the boxes of a poster).

This leads to the need for \captionof instead of \caption to put a caption inside a center environment. Is xtable capable of such a thing?

Heisenberg
  • 8,386
  • 12
  • 53
  • 102

1 Answers1

3

\caption is hard coded. See source of print.xtable.R.

if (tabular.environment == "longtable" && caption.placement == "top") {
            if (is.null(short.caption)){
                BCAPTION <- "\\caption{"
            } else {
                BCAPTION <- paste("\\caption[", short.caption, "]{", sep = "")
            }

Way around this would be to do gsub on the result before you pass it to the interpreter. Something along the lines of gsub("\\caption", "\captionof", x).

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Nice idea on `gsub`, but at which point do I insert it? I'm doing `print(xtable(my.df), file="my_table.tex")`. – Heisenberg Dec 01 '14 at 09:18
  • 1
    Save the `print` statement to a variable, run `gsub` through it and then export to `.tex` (for example using `cat(..., file = "my_table.tex")`. – Roman Luštrik Dec 01 '14 at 09:53
  • 1
    @Heisenberg -- [Here's an example](http://stackoverflow.com/questions/12148770/changing-the-color-of-negative-numbers-to-red-in-a-table-generated-with-xtable/12148962#12148962) that accomplishes this type of thing using `capture.output()`, `gsub()`, and `cat()`. – Josh O'Brien Dec 01 '14 at 15:42