如何为 RMarkdown 文档的不同部分设置字体样式和大小?

How to set up font style and size for different sections of RMarkdown document?

让我们看看下面的RMarkdown文档。

如何为这两个部分设置字体类型和大小,例如:

1 - "Arial, bold, 9pt" 第一节

2 - "Arial Narrow, bold, 8pt" 第二个。

谢谢!

---
title: "R Notebook"
output: pdf_document
---

## 1. First section with "First car name"

```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
# 1. Data
fist_car_name <- rownames(mtcars)[[1]]

# 2. Print name of the first car
cat(fist_car_name)
```

## 2. Second section with "Data about all cars"

```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(knitr)
library(kableExtra)

kable(mtcars)
```

我们可以在 Rmarkdown 中使用 LaTeX 代码。 \fontfamily 字体系列:phvHelvetica 并且类似于 Arial 但不需要额外的包。 \fontseries 用于字体类型:我们使用 b 表示粗体,bc 表示中等浓缩(其他值请参见 this tex.stackexchange answer). The font size we define with \small and \footnotesize which should correspond to 9pt and 8pt。要还原所有内容,我们使用 \rmfamily\normalsize

---
title: "R Notebook"
output: pdf_document
---
## 1. First section with "First car name"

\fontfamily{phv}\fontseries{b}\small

```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
# 1. Data
fist_car_name <- rownames(mtcars)[[1]]

# 2. Print name of the first car
cat(fist_car_name)
```

## 2. Second section with "Data about all cars"

\fontfamily{phv}\fontseries{bc}\footnotesize

```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(knitr)
library(kableExtra)

kable(mtcars)
```
## 3. Let's switch back to defaults

\rmfamily\normalsize

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod 
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

屈服