我想在书本文档中添加模型中的表(其他表除外),以使所有表自动编号。使用knitr::kable()
时效果很好。但是我无法使用模型表sjPlot::tab_model
的第一个选项或创建这些表的其他函数(例如stargazer::stargazer
和texreg::htmlreg
这是一个简单的.Rmd示例:
---
title: "Example"
output: bookdown::html_document2
---
Bookdown gets numbered tables when using `kable`.
```{r tab}
knitr::kable(head(mtcars),
caption = "First table")
```
But I want to make a `tab_model` table to be also automatically numbered in the document
```{r lm-tab1}
reg_mod <- lm(mpg ~ wt, data = mtcars)
sjPlot::tab_model(reg_mod, title = "Second table")
```
Optionally, I would like to be able to do it with other package for creating automatic model
tables, such as `stargazer::stargazer`, `texreg::htmlreg` or perhaps other suggestion
```{r lm-tab2, results='asis'}
stargazer::stargazer(reg_mod, type = "html", title = "Third table")
```
```{r lm-tab3, results='asis'}
texreg::htmlreg(reg_mod, caption = "Fourth table")
```
是否知道如何使tab_model
或任何其他函数用于回归模型以与书本编号一起使用?
答案 0 :(得分:3)
如documentation中所述,如果您在标题/标题中包含(\#tab:my-table-lab)
之类的标签,则bookdown会自动为其他功能生成的表格编号。
例如,通过您的tab_model
表,您可以执行以下操作:
reg_mod <- lm(mpg ~ wt, data = mtcars)
sjPlot::tab_model(reg_mod, title = "(\\#tab:tab-model-table) Second table")