如何使用 kableExtra 在 bookdown 中执行特定的 table
How to do specific table in bookdown with kableExtra
我尝试在 RMarkown 中使用 kableExtra 来获取文本 table,如下例所示:
text_tbl <- data.frame(
Items = c("Item 1", "Item 2", "Item 3"),
Features = c(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tempor ex. Morbi malesuada sagittis turpis, at venenatis nisl luctus a. ",
"In eu urna at magna luctus rhoncus quis in nisl. Fusce in velit varius, posuere risus et, cursus augue. Duis eleifend aliquam ante, a aliquet ex tincidunt in. ",
"Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis. "
)
)
kbl(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
不过,我想更改 table 的文本,方法是在一列中添加运算符,在另一列中添加带有一些解释的示例,完全针对此站点:https://www.tutorialspoint.com/r/r_operators.htm.
我生成了以下代码,但有一些变化,但没有用。
text_tbl <- data.frame(
Items = c(" <- ", " %in% "),
Features = c(
" Here it's an example: $x <- 3$",
" Here it's an example: $c(1, 1, 1, 2, 5, 8, 10) %in% 1$ "
)
)
kbl(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
我想说得更具体些:
1 - 如何在我将在由 kable() 创建的 table 中使用的数据框中添加运算符?
2 - 如何在由 kable() 创建的 table 中 运行 的数据框中添加代码?
我会在 rmarkdown 中执行这两个问题。
谢谢
也许这对你有帮助:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
```
```{r}
text_tbl <- data.frame(
Items = c(" $<-$ ", " $$\%$$in$$\%$$ "),
Features = c(
" Here it's an example: $x <- 3$",
" Here it's an example: $c(1, 1, 1, 2, 5, 8, 10) $$\%$$in$$\%$$ 1$ "
)
)
kbl(text_tbl, booktabs = T, escape = F) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
```
1 - escape = F
已添加到函数 kbl
2 - 要插入 %,您需要这样:$$\%$$
我尝试在 RMarkown 中使用 kableExtra 来获取文本 table,如下例所示:
text_tbl <- data.frame(
Items = c("Item 1", "Item 2", "Item 3"),
Features = c(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tempor ex. Morbi malesuada sagittis turpis, at venenatis nisl luctus a. ",
"In eu urna at magna luctus rhoncus quis in nisl. Fusce in velit varius, posuere risus et, cursus augue. Duis eleifend aliquam ante, a aliquet ex tincidunt in. ",
"Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis. "
)
)
kbl(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
不过,我想更改 table 的文本,方法是在一列中添加运算符,在另一列中添加带有一些解释的示例,完全针对此站点:https://www.tutorialspoint.com/r/r_operators.htm.
我生成了以下代码,但有一些变化,但没有用。
text_tbl <- data.frame(
Items = c(" <- ", " %in% "),
Features = c(
" Here it's an example: $x <- 3$",
" Here it's an example: $c(1, 1, 1, 2, 5, 8, 10) %in% 1$ "
)
)
kbl(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
我想说得更具体些:
1 - 如何在我将在由 kable() 创建的 table 中使用的数据框中添加运算符? 2 - 如何在由 kable() 创建的 table 中 运行 的数据框中添加代码?
我会在 rmarkdown 中执行这两个问题。
谢谢
也许这对你有帮助:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
```
```{r}
text_tbl <- data.frame(
Items = c(" $<-$ ", " $$\%$$in$$\%$$ "),
Features = c(
" Here it's an example: $x <- 3$",
" Here it's an example: $c(1, 1, 1, 2, 5, 8, 10) $$\%$$in$$\%$$ 1$ "
)
)
kbl(text_tbl, booktabs = T, escape = F) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
```
1 - escape = F
已添加到函数 kbl
2 - 要插入 %,您需要这样:$$\%$$