Reputation: 565
I use the following code from bookdown
package tutorial in R markdown file:
```{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'
)
```
Unlike the book, the code returns the result without space between two tables, like so.
In some questions I see the solutions with cat()
function and some html
injections.
(Also we need to set the option results = 'asis'
)
I wonder is there a more elegant and simple way to set some space between tables and preserve default html formatting at the same time?
Upvotes: 4
Views: 1672
Reputation: 9678
If you're not willing to do some tweaking using HTML/CSS, layout functions such as fluidRow()
and column()
from the Shiny package might help:
```{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"))
```
Upvotes: 1