How can I change the font family of a title in R with officer? I'm trying this with the function fp_text(font.family = "Arial")
, but the problem is that the title which I define with fp_text
does not end up in the table of contents.
Asked
Active
Viewed 2,202 times
1 Answers
1
It's kind of a pain, but the way I do it is:
- Add an empty placeholder in the title slot with
ph_empty()
- Add formatted text with
ph_add_fpar()
, usingfpar()
,ftext()
, andfp_text()
to create the formatted text object.
Here is an example of how to change the title on a Title Slide and on a Title and Content slide, assuming the fonts you want to use are "Rage Italic" and "Goudy Stout":
library(officer)
library(magrittr)
# the formatting you want to use goes here -- check your fonts()
format_main_title <- fp_text(font.family='Rage Italic', font.size=72)
format_page_title <- fp_text(font.family='Goudy Stout', font.size=24)
read_pptx() %>%
add_slide(layout = 'Title Slide', master='Office Theme') %>%
ph_empty(type='ctrTitle') %>%
ph_add_fpar(fpar(ftext('Fancy Main Title', prop=format_main_title)),
type = 'ctrTitle') %>%
add_slide(layout = 'Title and Content', master='Office Theme') %>%
ph_empty(type='title') %>%
ph_add_fpar(fpar(ftext('Fancy Page Title', prop=format_page_title)),
type = 'title') %>%
ph_with_text(type = 'body', str = 'Boring stuff goes here') %>%
print('test.pptx')
produces:
You can see these titles in the table of contents:
Having said that -- If you find yourself consistently changing title fonts to the same new formatting you would probably be better off creating a template deck with your own Slide Master (versus the default "Office Theme") that uses your desired font and beginning your chain with that (i.e., read_pptx('your_template.pptx') %>% etc.
)

C8H10N4O2
- 18,312
- 8
- 98
- 134
-
1This returns the error `Error: selection does not match any row in slide_summary. Use function slide_summary.` after the third line. – jarichardson Sep 20 '19 at 12:04