Hi so I have I am trying to write my own function that will automatically size and central align the images/tables that I am generating from officer. The top/left functions in the add_image and add_table are good when I add each table manually as The differing tables are differing sizes but I wasn't sure how to automatically do it for different shaped images and tables. I have the following code for images:
Image <- function(PP,title,footer,pageNO,path){
im <- load.image(path)
width <- imager::width(im)
height <- imager::height(im)
ratio <- width/height
if(ratio < 9.15 / 3.6){
y <- 3.6
x <- 3.6 * ratio
}
if(ratio >= 9.15 / 3.6){
y <- 9.15 / ratio
x <- 9.15
}
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_img(type = "body", src = path, height = y, width = x) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "sldNum", str = pageNO)
}
I would then like to align this image in the centre of the slide but am not sure how I would do this.
Then the same for tables but I have no idea how to do this as I would have to automatically rescale the width and height of columns based on original width and height of the flextable image as I wouldn't want to lose the aspect ratio unless there is a different way? Current code for this is: but it doesn't do any resizing:
Slide <- function(PP,title,footer,pageNO,table){
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_flextable(value = table, type = "body") %>%
ph_with_text(type = "sldNum", str = pageNO)
}
Many thanks in advance, any help would be greatly appreciated