首页 > 解决方案 > 如何在 R Markdown Powerpoint 中更改字体颜色

问题描述

我正在使用R Markdown创建 PowerPoint 演示文稿并想更改其中一张幻灯片中的字体颜色。我想知道这是否可能?它仅适用于一张幻灯片,因此不能在 PowerPoint 模板中更改。到目前为止,我发现的所有解决方案似乎都仅适用于HTMLPDF文档。

---
title: "Example"
author: ""
date: "09/07/2020"
output:
  powerpoint_presentation
---


## R Markdown

<span style="color: red;">
This is an R Markdown presentation. 
I would like this text in red.
</span>


---
title: "Example"
author: ""
date: "09/07/2020"
output:
  powerpoint_presentation
---


## R Markdown

\textcolor{red}{
This is an R Markdown presentation. 
I would like this text in red.}

标签: rmarkdownpowerpoint

解决方案


您可以按照 Rmarkdown Cook book 的第 8.3 章中的建议使用 {officedown} 和 {officer} 包来完成。

1-使用officedown::rpptx_document文档输出

2- 装载officedownofficer包装

3-创建样式以应用于块中的单个元素fp_text()

4-使用行代码应用样式

---
title: Style text with officedown
output:
  officedown::rpptx_document: default
---

`` `{r setup, include=FALSE}

knitr::opts_chunk$set(echo = FALSE)

library(officedown)
library(officer)

ft <- fp_text(color = 'red', bold = TRUE)
`` `

## R Markdown

This is an R Markdown presentation. 
`r ftext("I would like this text in red", ft)`.


推荐阅读