如何在 knitr::kable 中连续的表之间保留一些 space?
How to keep some space between tables in a row in knitr::kable?
我在 R markdown 文件中使用 bookdown
包 tutorial 中的以下代码:
```{r}
d1 <- head(cars, 3)
d2 <- head(mtcars[, 1:3], 5)
knitr::kable(
list(d1, d2),
caption = 'Two tables placed side by side.',
booktabs = TRUE, valign = 't'
)
```
与书上不同,代码returns两表之间没有space的结果,像这样。
在一些问题中,我看到了带有 cat()
函数和一些 html
注入的解决方案。
(我们还需要设置选项results = 'asis'
)
我想知道有没有更优雅和简单的方法来在表之间设置一些 space 并同时保留默认的 html 格式?
如果您不愿意使用 HTML/CSS 进行一些调整,fluidRow()
和 column()
等来自 Shiny 的布局函数软件包可能有帮助:
```{r, echo=F}
library(kableExtra)
library(shiny)
d2 <- head(mtcars[, 1:3], 5) %>% kable() %>% kable_styling()
fluidRow(
column(2, HTML(d2), offset = 2),
column(2, HTML(d2), offset = 2),
)
fluidRow(align = "center", column(12, "Figure 1: Two tables side by side"))
```
我在 R markdown 文件中使用 bookdown
包 tutorial 中的以下代码:
```{r}
d1 <- head(cars, 3)
d2 <- head(mtcars[, 1:3], 5)
knitr::kable(
list(d1, d2),
caption = 'Two tables placed side by side.',
booktabs = TRUE, valign = 't'
)
```
与书上不同,代码returns两表之间没有space的结果,像这样。
在一些问题中,我看到了带有 cat()
函数和一些 html
注入的解决方案。
(我们还需要设置选项results = 'asis'
)
我想知道有没有更优雅和简单的方法来在表之间设置一些 space 并同时保留默认的 html 格式?
如果您不愿意使用 HTML/CSS 进行一些调整,fluidRow()
和 column()
等来自 Shiny 的布局函数软件包可能有帮助:
```{r, echo=F}
library(kableExtra)
library(shiny)
d2 <- head(mtcars[, 1:3], 5) %>% kable() %>% kable_styling()
fluidRow(
column(2, HTML(d2), offset = 2),
column(2, HTML(d2), offset = 2),
)
fluidRow(align = "center", column(12, "Figure 1: Two tables side by side"))
```