如何在 RMarkdown 中使用 css 自定义段落

How to customize a paragraph with css in RMarkdown

---
title: "My study"
output:
  html_document:
    df_print: paged
---

我使用下面的代码来控制我整个文档的文本格式

<style type="text/css">
  body{
  font-size: 14pt;
  font-family: Garamond;
  line-height:1.8;
  
}
</style>

我现在想自定义某些段落或字幕

## SUBTITLE 1 (to color in blue)

.

## SUBTITLE 2 (to color in blue)

.

 { in italic and colored in brown and line-height=1
    My paragraph text My paragraph text My paragraph text My paragraph text My paragraph text
    My paragraph text My paragraph text My paragraph text My paragraph text My paragraph text
    }

2 级标题呈现为 h2 html 元素。要更改所有这些标题的颜色,您可以执行以下操作,这会将所有 ## {insert heading} 更改为蓝色字体。

h2 {
  color: blue;
}

要更改某些标题的颜色,您可以使用 html 标签创建它们并给它们一个 class。然后在CSS.

中更改class的样式

HTML:

<h2 class="purple-heading">Some heading</h2>

CSS:

.purple-heading {
  color: purple;
}

要设置某些段落的样式,请将它们包裹在 <p> 标签中并给它们一个 class。然后在 CSS.

中设置 class 的样式

HTML:

<p class="large-p">A long and very large paragraph.</p>

CSS:

.large-p {
  font-size: 96px;
}

整体降价文件:

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<style type="text/css">
  body{
  font-size: 14pt;
  font-family: Garamond;
  line-height:1.8;
  }
  
  h2 {
    color: blue;
  }
  .purple-heading {
    color: purple;
  }
  
  .large-p {
    font-size: 96px;
  }
</style>

## H2
<h2 class="purple-heading">Some heading</h2>
some un-styled text

<p class="large-p">A long and very large paragraph.</p>

如果您有很多东西需要设置样式(即使您没有),我建议将 html/markdown 与 CSS 分开。您可以创建一个 .css 文件并更改 YAML header 如下:

---
title: "test"
output: 
  html_document:
    css: your_path.css
---