I'm on week 1 of learning how to use Markdown for tables so please do bear with me.
Objective is to create three tables and export it as a single image with one table below another.
Till now I've been able to successfully create 3 tables in HTML as kable objects. To the best of my knowledge, kable allows the user to join tables but only side-by-side. Haven't been able to come across any documentation that allows for tables one below another
My only workaround till now is to export three individual tables as png images. Then use magick to read them and create a new image stacking one above another.
Result is fairly satisfactory but the table widths are not constant. leading to additional question of how to control table width? i understand that
table.attr = "style = 'width: 37%;'" allows for setting the width. What is the best method to specify the exact width in inches or pixels instead of a relative number?
require(styler) library(reprex) library(dplyr) library(kableExtra) library(knitr) library(magick) a <- mtcars[1:4,1:4] b <- mtcars[5:9,1:4] c <- mtcars[10:16,1:5] ax <- kable(a, format = "html", caption = "table1") %>% kable_classic(full_width = F) bx <- kable(b, format = "html", caption = "table2") %>% kable_classic(full_width = F) cx <- kable(c, format = "html", caption = "table3") %>% kable_classic(full_width = F) ax bx cx d <- kables(list(ax,bx,cx)) %>% kable_classic() save_kable(ax, file = "ax.png") save_kable(bx, file = "bx.png") save_kable(cx, file = "cx.png") save_kable(d, file = "d.png") image01 <- image_read("ax.png") image02 <- image_read("bx.png") image03 <- image_read("cx.png") image <- c(image01,image02,image03) image_info(image) image_stack <- image_append(image, stack = T) image_write(image_stack, "abcx.png", format = "png")
here's output with kables() command with each kable one next to another. this is not the desired outcome
below is the output with the magick solution. Unsatisfactory output since all the table widths are not constant.
Any suggestions on how to approach this situation?
side note: reprex kept giving me a R Code Execution error. It seems to be occurring whenever I include the kableExtra package
Error in `reprex_render_impl()`: ! This reprex appears to crash R Call `reprex()` again with `std_out_err = TRUE` to get more info Run `rlang::last_error()` to see where the error occurred.