问题
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