0

我正在尝试使用文档中的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

papaja::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         : "my@email.com"

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

4

1 回答 1

2

可能最通用的解决方案是在as_kable().

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

然后 PDF 如下所示: 在此处输入图像描述

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

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

然后 PDF 如下所示: 在此处输入图像描述

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

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

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

于 2021-07-26T22:05:41.963 回答