【问题标题】:Rmarkdown, bookdown, texreg and cross-referencingRmarkdown、bookdown、texreg 和交叉引用
【发布时间】:2020-01-19 22:44:21
【问题描述】:

在 bookdown 中途交叉引用 texreg 制作的表格。该表已正确编号,但交叉引用以“??”结尾在文本中。下面是一个 MRE。有没有办法解决这个问题,或者是否有其他包可以解决这个问题(stargazer 在 bookdown 中有同样的问题)。使用fig.cap 无效。

感谢您的帮助。

---
title: "bookdownTest"
author: "Richard Sherman"
date: "1/9/2020"
output: 
  bookdown::pdf_document2:
    fig_caption: yes
    toc: false
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r load libraries, include=FALSE}
library(texreg)
library(bookdown)
```

```{r lm, results='asis', star.symbol = "\\*", center = TRUE}
m1 <- lm(mpg ~ disp + cyl + hp, mtcars)
m2 <- lm(mpg ~ disp + hp, mtcars)
texreg(list(m1, m2), center = TRUE,
  caption="Linear model of mpg")
```

Results are in Table \@ref(tab:lm).

【问题讨论】:

    标签: r r-markdown bookdown texreg


    【解决方案1】:

    texreg() 有一个标签选项,可以让你设置标签,所以你可以这样做:

    texreg(list(m1, m2), center = TRUE,
      caption="Linear model of mpg",
      label="tab:lm")
    

    您可能一直依赖bookdown documentation 中描述的自动表格标签,但这仅在使用knitr::kable() 函数生成表格时有效。

    【讨论】:

    • 这就是答案;谢谢。我试过label="lm",但我没想过要试试label="tab:lm"
    猜你喜欢
    • 2023-02-01
    • 2020-08-09
    • 2020-01-05
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    • 2019-02-26
    • 2022-10-25
    相关资源
    最近更新 更多