1

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
  • 131
  • 1
  • 11
  • 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

1

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
  • 16,126
  • 5
  • 18
  • 49
  • hi, @AndrewGb , what if we want one table upon the other ? (horizontaly) ? – Larissa Cury Sep 27 '22 at 15:46
  • @LarissaCury If you just need them above and below each other for knitting an RMarkdown, then you can just run the 2 tables as different statements rather than combining them, i.e., `kable(caption = "Left Table", head(cars)) %>% kable_styling(); kable(caption = "Right Table", head(iris)) %>% kable_styling()`. – AndrewGB Sep 27 '22 at 16:24
  • hi, @AndrewGB , thank you! the problem is that I have a lot of tables ( > 10) , that's why they're in the list... https://stackoverflow.com/questions/73870622/plot-a-list-of-tables-vertically-kableextra-and-kable-in-r?noredirect=1&lq=1 any ideas? – Larissa Cury Sep 27 '22 at 16:52