在 bookdown gitbook 中更改 R 块背景颜色

问题描述

我想在 bookdown gitbook 中更改 R 块和 R 块输出的背景颜色。尝试遵循 https://bookdown.org/yihui/rmarkdown-cookbook/chunk-styling.html 第 7.3 节、Changing chunk background color in RMarkdownhttps://github.com/yihui/knitr-examples/blob/master/116-html-class.Rmd

但没有成功。

我从这里编辑了最小的例子:https://github.com/rstudio/bookdown-demostyle.css

.Rchunk {
  background-color: #f2dede;
  font-weight: bolder;
  color: red;
}

.Rout {
  background-color: #d9edf7;
  font-weight: bolder;
  color: blue;
}

这在 index.Rmd 周围 # Prerequisite

```{r,echo=FALSE}
knitr::opts_chunk$set(fig.align='center',out.width='60%',class.source="Rchunk",class.output="Rout",comment="",prompt=TRUE) 
```


# Prerequisites

```{r}
summary(iris$Sepal.Length)
``` 

如第一张图片所示,类在 html 文件中传递,显示了 font-weight: bolder; 但不显示字体和背景颜色。它实际上就在那里,但被屏蔽了,只是另一种 css 样式

.book .book-body .page-wrapper .page-inner section.normal pre {
    overflow: auto;
    word-wrap: normal;
    margin: 0 0 1.275em;
    padding: .85em 1em;
    background: #f7f7f7;
}

有没有办法去除灰色背景调用,以便可以显示彩色类?

Grey background

Colorful background

解决方法

感谢@cderv 为我指明了正确的方向。只需要将 !important 添加到我想要优先考虑的 css 样式中:

.Rchunk {
  background-color: #f2dede !important;
  font-weight: bolder;
  color: red !important;
}

.Rout {
  background-color: #d9edf7 !important;
  font-weight: bolder;
  color: blue !important;
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...