Caption not appearing for LaTeX table when knitting using Hmisc LaTeX Function

我的未来我决定 提交于 2019-12-10 23:59:28

问题


I am trying to create a LaTeX table using the table and Hmisc packages however, I am having trouble getting the caption to appear.

Here is a reproducible example:

    ```{r, results = "asis"}

# data:
dow <- sample(1:7, 100, replace=TRUE)
purp <- sample(1:4, 100, replace=TRUE)
dow <- factor(dow, 1:7, c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"))
purp <- factor(purp, 1:4, c("Business", "Commute", "Vacation", "Other"))

dataframe <-  data.frame( dow, purp)

# The packages
library(tables)
library(Hmisc)

# The table
#tabular(  (Weekday=dow) ~  (Purpose=purp)*(Percent("row")+ 1)    ,data=dataframe        )

# The latex table
tab <- latex(  tabular(  (Weekday=dow) ~  (Purpose=purp)*(Percent("col")+ 1)    ,data=dataframe        ), caption = "This is a Caption")
print(tab)
```

The knitted table does not contain the caption. I am new to LaTeX and my only experience with LaTeX is through R and Rstudio. Any advice would be greatly appreciated.


回答1:


when you run

tab <- latex(tabular(  (Weekday=dow) ~  (Purpose=purp)*(Percent("col")+ 1), data=dataframe), caption = "This is a Caption")

you are using the default S3 method which in this case is latex.tabular

## S3 method for class 'tabular'
latex(object, file = "", options = NULL, append = FALSE, ...)

latex.tabular does not take a caption argument



来源:https://stackoverflow.com/questions/44526634/caption-not-appearing-for-latex-table-when-knitting-using-hmisc-latex-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!