【问题标题】:How can i change in R the font family of a Title with officer?如何在 R 中更改带有官员的标题的字体系列?
【发布时间】:2018-11-16 11:32:42
【问题描述】:

如何在 R 中使用官员更改标题的字体系列?我正在尝试使用函数fp_text(font.family = "Arial"),但问题是我使用fp_text 定义的标题并没有出现在目录中。

【问题讨论】:

    标签: r xml ggplot2 officer


    【解决方案1】:

    这有点痛苦,但我这样做的方式是:

    1. 在标题栏添加一个空的占位符ph_empty()
    2. 使用ph_add_fpar() 添加格式化文本,使用fpar()ftext()fp_text() 创建格式化文本对象。

    以下是如何更改标题幻灯片以及标题和内容幻灯片上的标题的示例,假设您要使用的字体是“Rage Italic”和“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')
    

    产生:

    您可以在目录中看到这些标题:

    话虽如此 - 如果您发现自己不断将标题字体更改为相同的新格式,您最好使用您自己的幻灯片母版(而不是默认的“Office 主题”)创建一个模板组,该模板使用您想要的字体并以此开始您的连锁店(即read_pptx('your_template.pptx') %&gt;% etc.

    【讨论】:

    • 这会在第三行之后返回错误Error: selection does not match any row in slide_summary. Use function slide_summary.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多