如何使用 revealjs_presentation 的 R Markdown 更改字体?
How to change fonts using revealjs_presentation of R Markdown?
我想在使用 R Markdown 的 revealjs_presentation
制作的演示文稿中使用 Noto Sans JP, or also called Source Han Serif OTF Japanese。下图将告诉您字体的形状。
由于Google提供了一个css of the font,我把它的URL放到YAML部分的output: revealjs::revealjs_presentation: css
中。但是,knitr
仍使用默认字体生成 HTML 幻灯片,如下所示。那么,使用R Markdown 获取HTML 幻灯片时,应该如何指定字体呢?
我尝试过的 (MWE)
---
title: |
| タイトル
subtitle: |
| <small> テスト </small>
author: |
| @CLRafaelR
date: "`r format(Sys.time(), '%Y年 %B %e日')`"
output:
revealjs::revealjs_presentation:
css: https://fonts.googleapis.com/earlyaccess/notosansjapanese.css
self_contained: true
---
# R Markdown
あいうえお
## R Markdown
これはRマークダウンのプレゼンテーションです。
マークダウンとは、HTML、PDF、MS Wordの書類を作成する際に使える簡単な記法です。
R Markdownに関する詳細は、<http://rmarkdown.rstudio.com>をご覧ください。
This is an R Markdown presentation.
Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.
For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
## Slide with Bullets
あいうえお
- 甲
- 乙
- 丙
> - 丁
> - 戊
> - 己
## Slide with R Code and Output
```{r}
summary(cars)
```
## Slide with Plot
```{r, echo=FALSE}
plot(cars)
```
备注
其实我在下面的路径下有Source Han Sans
的otf文件。有没有办法在R Markdown中调用本地字体路径?
C:/Users/my-true-user-name/AppData/Local/Microsoft/Windows/Fonts
sessionInfo()
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Japanese_Japan.932 LC_CTYPE=Japanese_Japan.932 LC_MONETARY=Japanese_Japan.932
[4] LC_NUMERIC=C LC_TIME=Japanese_Japan.932
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.2 rsconnect_0.8.16 htmltools_0.4.0 tools_3.6.2 revealjs_0.9 yaml_2.2.1
[7] Rcpp_1.0.3 rmarkdown_2.1 knitr_1.28 xfun_0.12 digest_0.6.25 packrat_0.5.0
[13] rlang_0.4.4 evaluate_0.14
答案在 Google Fonts' Noto Sans JP page...
只需复制以下代码并粘贴到 Rmd 文件的非 YAML 部分即可。
最终 MWE
---
title: |
| タイトル
subtitle: |
| <small> テスト </small>
author: |
| @CLRafaelR
date: "`r format(Sys.time(), '%Y年 %B %e日')`"
output:
revealjs::revealjs_presentation:
self_contained: true
---
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100;300;400;500;700;900&display=swap');
</style>
```{css css-settings, echo=FALSE}
.reveal h1,
.reveal h2,
.reveal h3,
.reveal h4,
.reveal h5,
.reveal h6 {
font-family: 'Noto Sans JP', sans-serif;
}
.reveal .slide {
font-family: 'Noto Sans JP', sans-serif;
}
```
# R Markdown
あいうえお
## R Markdown
これはRマークダウンのプレゼンテーションです。
マークダウンとは、HTML、PDF、MS Wordの書類を作成する際に使える簡単な記法です。R Markdownに関する詳細は、<http://rmarkdown.rstudio.com>をご覧ください。
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
## Slide with Bullets
あいうえお
- 甲
- 乙
- 丙
> - 丁
> - 戊
> - 己
## Slide with R Code and Output
```{r}
summary(cars)
```
## Slide with Plot
```{r, echo=FALSE}
plot(cars)
```
我想在使用 R Markdown 的 revealjs_presentation
制作的演示文稿中使用 Noto Sans JP, or also called Source Han Serif OTF Japanese。下图将告诉您字体的形状。
由于Google提供了一个css of the font,我把它的URL放到YAML部分的output: revealjs::revealjs_presentation: css
中。但是,knitr
仍使用默认字体生成 HTML 幻灯片,如下所示。那么,使用R Markdown 获取HTML 幻灯片时,应该如何指定字体呢?
我尝试过的 (MWE)
---
title: |
| タイトル
subtitle: |
| <small> テスト </small>
author: |
| @CLRafaelR
date: "`r format(Sys.time(), '%Y年 %B %e日')`"
output:
revealjs::revealjs_presentation:
css: https://fonts.googleapis.com/earlyaccess/notosansjapanese.css
self_contained: true
---
# R Markdown
あいうえお
## R Markdown
これはRマークダウンのプレゼンテーションです。
マークダウンとは、HTML、PDF、MS Wordの書類を作成する際に使える簡単な記法です。
R Markdownに関する詳細は、<http://rmarkdown.rstudio.com>をご覧ください。
This is an R Markdown presentation.
Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.
For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
## Slide with Bullets
あいうえお
- 甲
- 乙
- 丙
> - 丁
> - 戊
> - 己
## Slide with R Code and Output
```{r}
summary(cars)
```
## Slide with Plot
```{r, echo=FALSE}
plot(cars)
```
备注
其实我在下面的路径下有Source Han Sans
的otf文件。有没有办法在R Markdown中调用本地字体路径?
C:/Users/my-true-user-name/AppData/Local/Microsoft/Windows/Fonts
sessionInfo()
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Japanese_Japan.932 LC_CTYPE=Japanese_Japan.932 LC_MONETARY=Japanese_Japan.932
[4] LC_NUMERIC=C LC_TIME=Japanese_Japan.932
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.2 rsconnect_0.8.16 htmltools_0.4.0 tools_3.6.2 revealjs_0.9 yaml_2.2.1
[7] Rcpp_1.0.3 rmarkdown_2.1 knitr_1.28 xfun_0.12 digest_0.6.25 packrat_0.5.0
[13] rlang_0.4.4 evaluate_0.14
答案在 Google Fonts' Noto Sans JP page... 只需复制以下代码并粘贴到 Rmd 文件的非 YAML 部分即可。
最终 MWE
---
title: |
| タイトル
subtitle: |
| <small> テスト </small>
author: |
| @CLRafaelR
date: "`r format(Sys.time(), '%Y年 %B %e日')`"
output:
revealjs::revealjs_presentation:
self_contained: true
---
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100;300;400;500;700;900&display=swap');
</style>
```{css css-settings, echo=FALSE}
.reveal h1,
.reveal h2,
.reveal h3,
.reveal h4,
.reveal h5,
.reveal h6 {
font-family: 'Noto Sans JP', sans-serif;
}
.reveal .slide {
font-family: 'Noto Sans JP', sans-serif;
}
```
# R Markdown
あいうえお
## R Markdown
これはRマークダウンのプレゼンテーションです。
マークダウンとは、HTML、PDF、MS Wordの書類を作成する際に使える簡単な記法です。R Markdownに関する詳細は、<http://rmarkdown.rstudio.com>をご覧ください。
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
## Slide with Bullets
あいうえお
- 甲
- 乙
- 丙
> - 丁
> - 戊
> - 己
## Slide with R Code and Output
```{r}
summary(cars)
```
## Slide with Plot
```{r, echo=FALSE}
plot(cars)
```