我想在我的 kable 表中换行长文本。下面是一个简单的表格示例,其中的列文本太长,需要换行以使表格适合页面。
---
title: "test"
output: pdf_document
---
```{r setup, include=FALSE}
library(knitr)
```
This is my test
```{r test, echo=FALSE}
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))
kable(test)
```
最佳答案
除了很棒的 pander
包之外,另一种解决方案是在 kableExtra
中使用 column_spec
。在这种情况下,下面的代码就可以解决问题。
kable(test, "latex") %>%
column_spec(1, width = "10em")
关于r - 将长文本换行到 kable 表列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29425499/