RMarkdown - Change Inline Code Color

早过忘川 提交于 2019-12-05 22:53:56

Or you can use text_spec in kableExtra. It literarily does the same thing but just a tiny bit more literal. See more here

---
title: ''
output: html_document
---

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

## R Markdown

This is an R Markdown document. 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>.

This is inline code: `r text_spec(colnames(mtcars)[1], color = "red")`.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

### This is more inline code `r text_spec(colnames(mtcars)[2], color = "red")`.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

You can do something like:

---
title: ''
output: html_document
---

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

```{css echo=FALSE}
.custom-inline {
  color: red;
  font-weight: 700
}
```
## R Markdown

This is an R Markdown document. 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>.

This is inline code: `r sprintf("<span class='custom-inline'>%s</span>", colnames(mtcars)[1])`.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

### This is more inline code `r sprintf("<span class='custom-inline'>%s</span>", colnames(mtcars)[2])`.

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

to get:

The default templates do not wrap inline chunks in a classed <span> tag so you have to do it manually. You can make a function to do it, too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!