0

I've made a flextable with various formatting, but when I add to the PowerPoint, the table is outside the slide size.

I'm not sure if I have to just go through and set the column & row sizes, or if there is something I should set up in my PowerPoint template master settings. I saw where you can set column and row sizes, but nothing about the overall flextable dimensions.

Code below.

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")

This makes the table too big. I can resize it and the table still looks great, just trying to find what I'm missing.

Demo PowerPoint

James Holland
  • 1,102
  • 10
  • 17

2 Answers2

0

One option is to set the defaults and change the font.size a la:

set_flextable_defaults(
  font.size = 28
)

within your chunk.

boshek
  • 4,100
  • 1
  • 31
  • 55
0

You could also base some of the flextable parameters on a condition like the number of rows (nrow()) or character count (nchar()) of the source df.

#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)

A similar method could also be used to subset the table and place additional rows on an additional slide.

Misfit6
  • 39
  • 1