Search code examples
rformattingalignmentr-markdownflextable

Align multiple tables side by side using the flextable R package in R markdown


Folks, how do I align multiple tables side by side using the flextable R package in R markdown?

---
title: "flextables side by side"
output:
word_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flextable)
library(dplyr)
```
## Please, plot these tables side by side!
```{r pressure, echo=FALSE}
flextable(pressure[1:7,])%>% set_caption(caption = "Table 1")
flextable(cars[1:5,])%>% set_caption(caption = "Table 2")
```

There are examples for other packages:

Align multiple tables side by side

Rmarkdown side-by-side tables spacing


Solution

  • This works for me.

    library(webshot)
    flextable(pressure[1:7,])%>% set_caption(caption = "Table 1") %>% save_as_image("tmp1.png")
    flextable(cars[1:5,])%>% set_caption(caption = "Table 2") %>% save_as_image("tmp2.png")
    knitr::include_graphics(c("tmp1.png", "tmp2.png"))
    

    enter image description here