我使用 bookdown
包 tutorial 中的以下代码在 R markdown 文件中:
```{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'
)
```
与书不同,代码返回结果时两个表之间没有空格,就像这样。
在一些问题中,我看到了带有 cat()
函数和一些 html
注入(inject)的解决方案。
(我们还需要设置选项 results = 'asis'
)
我想知道是否有更优雅、更简单的方法来设置表格之间的一些空间并同时保留默认的 html 格式?
最佳答案
如果您不愿意使用 HTML/CSS 进行一些调整,Shiny< 中的 fluidRow()
和 column()
等布局函数/em> 包可能有帮助:
```{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"))
```
关于css - 如何在 knitr::kable 中连续的表之间保留一些空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64505980/