0

I would like to display multiple tables side by side in Viewer/html. One way I found is using kable and specifying the list of datatables like so below, but the formatting is lost when a list of datatables are displayed versus displaying just a single datatable. Is there a way to retain kable formating and possibly add more formatting to make tables more differentiable with lines and spacing? Or is there another way to display side by side multiple tables in one Viewer/html besides kable? Thanks!

Example with displaying multiple tables where formatting is lost:

kable(list(head(cars), head(iris))) %>%
  kable_styling()

Formatting retained when only one table is displayed:

kable(head(cars)) %>%
  kable_styling()
user2272972
  • 97
  • 1
  • 6
  • Does this help? https://stackoverflow.com/questions/38036680/align-multiple-tables-side-by-side – AndrewGB Dec 03 '21 at 07:06
  • The float option does help partly. However, I'm not working in`rmarkdown` , would it be possible to display the side by side float tables in a single Viewer or html file? Thanks. – user2272972 Dec 03 '21 at 17:52

1 Answers1

0

You can use knitr::kables to get two tables side by side in the Viewer. Further, it will also work for knitting to HTML (or saving as HTML from the RStudio Viewer).

library(tidyverse)
library(kableExtra)

knitr::kables(list(
  kable(caption = "Left Table",
        head(cars)) %>% kable_styling(),
  kable(caption = "Right Table",
        head(iris)) %>% kable_styling()
)) %>%
  kable_styling()

Output

enter image description here

AndrewGB
  • 12,571
  • 4
  • 13
  • 38