table caption stays below for xtableFtable in R

时间:2018-03-23 00:49:22

标签: r latex xtable

I'm trying to use xtableFtable with print to make a LaTeX table with the caption on top. I've tried several different variations of what the documentation says about how to change the caption placement within the print function, but print (as well as print.xtableFtable) ignores what I enter for this parameter and uses its default value (which is "bottom").

Here's my code:

data(mtcars)

mtcars$cyl <- factor(mtcars$cyl, 
              levels = c("4", "6", "8"), 
              labels = c("four", "six", "eight"))

tbl <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, 
              col.vars = c(2, 3), 
              dnn = c("Cylinders", "V/S", "Transmission"))

xftbl <- xtableFtable(tbl, 
              method = "non.compact",
              label = "my_table",
              caption = "My Table")

print(xftbl, booktabs = TRUE, 
              caption.placement = getOption("xtable.caption.placement", "top"))

I've also tried these two different variations for the caption placement parameter, but got the same result as above:

print(xftbl, booktabs = TRUE, caption.placement = "top")

and

print(xftbl, booktabs = TRUE,  xtable.caption.placement = "top")

All the other parameters appear to work properly, including booktabs. What am I doing wrong with the caption.placement parameter?

0 个答案:

没有答案