使用 gt 编织为 pdf 时,表格中的文本换行

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

抱歉,如果这是一个非常微不足道的问题,但我在互联网上查找并找不到答案。我正在使用 markdown 中的 gt 包制作一个基本表格。但在编织到 *.pdf 时,我似乎无法让文本换行。任何帮助将不胜感激!

table_data %>% gt()
r-markdown gt
1个回答
6
投票

不是答案,而是一个可重现的工作示例。

---
title: "Test"
output: pdf_document
---

```{r test, echo=FALSE, warning = FALSE}
library(tidyverse)
library(gt)

test <- data.frame(v1=c(
  "This is a long string. This is a long string. This is a long string. This is a long string. This is a long string.",
  "This is a another long string. This is a another long string. This is a another long string. This is a another long string. This is a another long string."),
                   v2=c(1, 2))
test %>% gt()
```

结果:

我最终选择了

kableExtra
。对于可重现的工作示例,将
test %>% gt()
替换为
test %>% kable() %>% kable_styling(full_width = TRUE)

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