[英]`gtsummary` and `papaja` integration for `kable` tables
我正在嘗試在papaja::apa6_pdf
文檔中使用gtsummary
表來包含格式化(帶標題)的kable
表。 但是,它沒有按預期呈現。 相比之下, gtsummary
kable
表在普通rmarkdown::pdf_document
kable
中呈現得很好(盡管gtsummary
kableExtra
表看起來也不太好)。 我很感激關於如何讓gtsummary
和papaja
很好地協同工作以生成“漂亮”的 PDF 表格的任何建議。 謝謝!
```
---
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()
```
```
---
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()
```
你可以切換到papaja自己的表函數apa_table()
來打印你想要的表:
trial %>%
tbl_summary(by = trt) %>%
as_tibble() %>%
apa_table(
caption = "This is a table about trials",
format.args = list(na_string = ""),
format = "pandoc"
)
我們首先必須通過as_tibble()
將tbl_summary()
的輸出轉換為as_tibble()
。 然后,我們可以像處理任何其他數據幀一樣處理它:
標題必須直接包含在對apa_table()
的調用中。 format.args = list(na_string = "")
確保NA
在表中不呈現為"NA"
,但作為一個空字符串。 最后, format = "pandoc"
確保正確處理降價語法(粗體)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.