嗨所以我有我正在尝试编写自己的函数,该函数将自动调整大小并集中对齐我从官员生成的图像/表格。当我手动添加每个表格时,add_image 和 add_table 中的顶部/左侧功能很好,因为不同的表格大小不同,但我不确定如何为不同形状的图像和表格自动执行此操作。我有以下图像代码:
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)
}
然后我想将此图像对齐在幻灯片的中心,但我不确定我会如何做到这一点。
然后对于表格也是如此,但我不知道如何执行此操作,因为我必须根据 flextable 图像的原始宽度和高度自动重新调整列的宽度和高度,因为我不想失去纵横比,除非有是不同的方式吗?当前的代码是:但它不做任何调整大小:
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)
}
非常感谢提前,任何帮助将不胜感激