`kable` 表的 `gtsummary` 和 `papaja` 集成

问题描述

我正在尝试在 gtsummary 文档中使用 papaja::apa6_pdf 表来包含格式化(带标题kable 表。但是,它没有按预期呈现。相比之下,gtsummary kable 表在普通 rmarkdown::pdf_document 中呈现得很好(尽管 gtsummary kableExtra 表看起来也不太好)。对于如何让 gtsummarypapaja 很好地协同工作以生成“漂亮”的 PDF 表格的任何建议,我将不胜感激。谢谢!

rmarkdown::pdf_document

```
---
title: "gtsummary + rmarkdown::pdf_document"
output: pdf_document
---
```
```{r}
library(gtsummary)

trial %>%
  tbl_summary(by = trt) %>%
  modify_caption("This is a table about trials") %>% 
  as_kable()

trial %>%
  tbl_summary(by = trt) %>%
  modify_caption("This is another table about trials") %>% 
  as_kable_extra()
```

gtsummary-pdf_output

木瓜::apa6_pdf

```
---
title             : "gtsummary + papaja"
shorttitle        : "gtsummary + papaja"

author: 
  - name          : "First Author"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Postal address"
    email         : "[email protected]"

affiliation:
  - id            : "1"
    institution   : "Wilhelm-Wundt-University"


authornote: >

abstract: "my abstract"
  
keywords          : "keywords"
wordcount         : "X"

bibliography      : []

floatsintext      : no
figurelist        : no
tablelist         : no
footnotelist      : no
linenumbers       : yes
mask              : no
draft             : no

documentclass     : "apa6"
classoption       : "man"
output            : papaja::apa6_pdf
---

```{r}
library(papaja)
library(gtsummary)

trial %>%
  tbl_summary(by = trt) %>%
  modify_caption("This is a table about trials") %>% 
  as_kable()

trial %>%
  tbl_summary(by = trt) %>%
  modify_caption("This is another table about trials") %>% 
  as_kable_extra()
```

gtsummary-papaja

解决方法

可能最通用的解决方案是在 as_kable() 中指定表格输出格式。

trial %>%
  tbl_summary(by = trt) %>%
  modify_caption("This is a table about trials") %>%
  as_kable(format = 'pipe')

PDF 如下所示: enter image description here

这似乎也适用于粗体标签:

trial %>%
  tbl_summary(by = trt) %>%
  modify_caption("This is a table about trials") %>%
  bold_labels() %>%
  as_kable(format = 'pipe')

PDF 如下所示: enter image description here

P.S.:也可以全局指定表格输出格式。在 papaja 文档中,您可以将以下行添加到您的 setup 块中。

options(knitr.table.format = 'pipe')

如果添加,则您可以完全省略对 as_kable() 的调用(但会打印一条警告消息)。