将自定义CSS标记添加到RMarkdown html文档 [英] Adding custom CSS tags to an RMarkdown html document

查看:149
本文介绍了将自定义CSS标记添加到RMarkdown html文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RMarkdown文档,输出为HTML,格式与以下示例相同.我该在哪里添加对每个绘图输出应用唯一的CSS ID或类的地方?

I have an RMarkdown document outputting to HTML of the same form as the below example. What do I add where to apply unique CSS ids or classes to each plot output?

---
title: "RMarkdown"
author: "Me"
date: "Friday, March 27, 2015"
output:
  html_document:
    theme: null
    css: style.css
---

```{r plot1, echo=FALSE, warning=FALSE, message=FALSE}
library(ggplot2)
x <- ggplot(some_r_code)
print(x)
```

```{r plot2, echo=FALSE, warning=FALSE, message=FALSE}
y <- ggplot(some_more_r_code)
print(y)
```

我已经阅读了 http://rmarkdown.rstudio.com/html_document_format.html 回答了这个问题,但没有让我到达那里.我有一个类似的问题,引用该页面的评论"部分中的材料,希望能得到其中的一个答案.

I've read the info page at http://rmarkdown.rstudio.com/html_document_format.html that went a ways to answering this question but didn't get me there. I have a similar question referencing the material in that page in it's comment section, and would appreciate an answer on either.

谢谢!

推荐答案

您可以使用results="asis"告诉knitr(在后台使用)直接将块的输出嵌入到html中.在块中,您可以使用cat来简单地编写一个样式标签,其中包括您的css定义:

You can tell knitr (which is used under the hood) with results="asis" to embed a chunk's output directly into the html. Within the chunk you can use cat to simply write a style tag including your css definitions:

```{r results="asis"}
cat("
<style>
h1 {
   color: red;
}
</style>
")
```

有关详细信息,请参见 http://yihui.name/knitr/options/#chunk_options

See http://yihui.name/knitr/options/#chunk_options for details.

这篇关于将自定义CSS标记添加到RMarkdown html文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆