繁体   English   中英

使 Flextable 适合 PowerPoint 中的幻灯片大小与官员

[英]Fit Flextable to slide size in PowerPoint with officer

我制作了一个具有各种格式的 flextable,但是当我添加到 PowerPoint 时,表格超出了幻灯片的大小。

我不确定我是否必须通过 go 并设置列和行大小,或者是否应该在我的 PowerPoint 模板主设置中进行设置。 我看到你可以在哪里设置列和行的大小,但没有关于整个 flextable 的尺寸。

代码如下。

library(officer)
library(rvg)
library(flextable)
library(tidyverse)
library(data.table)


pColor <- "#3c5cb0"
std_border = fp_border(color="gray")

outSatTbl <- flextable(head(iris, 19))

outSatTbl <- 
  outSatTbl %>%
  bg(bg = pColor, part = "header") %>% 
  color(color = "white", part = "header") %>%
  merge_h(part = "header") %>%
  add_header_lines(values = "Demo Table") %>%
  align(align = "center", part = "header") %>%
  align(align = "center", part = "body") %>%
  hline(part="body", border = std_border ) %>%
  autofit()


# ---------- Get PowerPoint template and initiate ---------- #


setwd("C:/.../WorkingFolder")

demo <- read_pptx("Rtest.pptx")


# ---------- Add Inpatient table to Power Point ----------- #

demo  <- add_slide(demo , layout = "Title and Content", master = "Theme1") %>%
  ph_with(outSatTbl, location = ph_location_type(type = "body"), use_loc_size = T) %>%
  


print(mho, target = "first_example.pptx")

这使得桌子太大。 我可以调整它的大小,桌子看起来仍然很棒,只是想找到我缺少的东西。

演示幻灯片

一种选择是设置默认值并更改font.size a la:

set_flextable_defaults(
  font.size = 28
)

在你的块内。

您还可以根据源 df 的行数 (nrow()) 或字符数 (nchar()) 等条件创建一些 flextable 参数。

#not run
iris_subset <- ...subset of iris...

if(nrow(iris_subset)>16){
   new_fontsize <- something_smaller
}else{
   new_fontsize <- current_fontsize
}

outSatTbl <- 
   flextable(iris_subset) %>%
   fontsize(size = new_fontsize, part="body)

也可以使用类似的方法来对表格进行子集化并在附加幻灯片上放置附加行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM