如何为 modelsummary R 包的输出表生成 pdf 格式的交叉引用?

问题描述 投票:0回答:1

我在下面编写了 R Markdown 块,输出的 pdf 显示了表 ??。我还没有找到解决这个问题的方法。我检查了这篇文章中给出的答案,但问题与pdf无关。

---
title: 'A title'
author: "Me"
output:
  bookdown::pdf_document2:
    latex_engine: pdflatex
    dev: cairo_pdf
    toc: false
    keep_tex: true
header-includes:
  - \usepackage{mathptmx}
  - \usepackage[T1]{fontenc}
  - \usepackage{xcolor}
lang: ES-es
linkcolor: red
---

Results are shown in Table \@ref(tab:table1)

```{r table1, echo=FALSE}
modelsummary(model_list,
             escape = TRUE,
             shape = term ~ model + statistic,
             estimate = "estimate",
             statistic = c("std.error", "p.value"),
             gof_map = c("aic"),
             coef_rename = c("anchura" = "Anchura",
                             "peso" = "Peso",
                             "color_f3" = "Color medio",
                             "color_f4" = "Color medio oscuro",
                             "color_f5" = "Color oscuro",
                             "estado_espina_f2" = "Estado regular",
                             "estado_espina_f3" = "Estado malo"),
             title = "Results")

```

我尝试了这个技巧:

title = "\\label{fig:table1}"
,编织了三遍,但没有成功。

r r-markdown modelsummary
1个回答
0
投票

一种可能的选择是使用

title = "(\\#tab:table1)Results"
并设置
escape=FALSE

使用

modelsummary
中的默认示例:

---
title: 'A title'
author: "Me"
output:
  bookdown::pdf_document2:
    latex_engine: pdflatex
    dev: cairo_pdf
    toc: false
    keep_tex: true
header-includes:
  - \usepackage{mathptmx}
  - \usepackage[T1]{fontenc}
  - \usepackage{xcolor}
lang: ES-es
linkcolor: red
---

```{r include=FALSE}
library(modelsummary)
```

```{r include=FALSE}
url <- "https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv"
dat <- read.csv(url)
dat$Small <- dat$Pop1831 > median(dat$Pop1831)
dat <- dat[
  ,
  c("Donations", "Literacy", "Commerce", "Crime_pers", "Crime_prop", "Clergy", "Small")
]

model_list <- list(
  "I" = lm(Donations ~ Literacy + Clergy, data = dat),
  "II" = lm(Crime_pers ~ Literacy + Clergy, data = dat),
  "III" = lm(Crime_prop ~ Literacy + Clergy, data = dat),
  "IV" = glm(Crime_pers ~ Literacy + Commerce, family = poisson, data = dat),
  "V" = glm(Donations ~ Literacy + Commerce, family = poisson, data = dat)
)
```

Results are shown in Table \@ref(tab:table1)

```{r table1, echo=FALSE}
modelsummary(model_list,
  escape = FALSE,
  estimate = "estimate",
  statistic = c("std.error", "p.value"),
  gof_map = c("aic"),
  title = "(\\#tab:table1)Results"
)
```

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.