简体   繁体   English

Rmarkdown、bookdown、texreg 和交叉引用

[英]Rmarkdown, bookdown, texreg and cross-referencing

Cross-referencing a table made by texreg in bookdown halfway works.在 bookdown 中途交叉引用texreg制作的表格。 The table is numbered properly but the cross-reference ends up as '??'该表已正确编号,但交叉引用最终为“??” in the text.在文中。 A MRE is below.下面是一个 MRE。 Is there a solution to this, or is there another package that can solve this problem ( stargazer has the same problem in bookdown).是否有解决方案,或者是否有另一个包可以解决这个问题( stargazer在 bookdown 中也有同样的问题)。 Using fig.cap has no effect.使用fig.cap没有效果。

Thanks for any help.谢谢你的帮助。

---
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).

texreg() has a label option that lets you set the label, so you can do: texreg()有一个标签选项,可以让你设置标签,所以你可以这样做:

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

You may have been relying on the automatic table labels described in the bookdown documentation , but that only works when using the knitr::kable() function to generate your table.您可能一直依赖bookdown 文档中描述的自动表格标签,但这仅在使用knitr::kable()函数生成表格时才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM