2017-05-08 30 views
1

我试图在由Rmarkdown生成的HTML文档中添加一个目录。首先,我发现this answer,这似乎是一个简单的方法,在HTML文件中添加CSS文件丝毫验证码:在Rmarkdown的HTML文档的左侧添加一个目录

#TOC { 
    position: fixed; 
    left: 0; 
    top: 0; 
    width: 200px; 
    height: 100%; 
    overflow:auto; 
} 
body { 
    max-width: 800px; 
    margin: auto; 
    margin-left:210px; 
    line-height: 20px; 
} 

但我想修改从Rmarkdown的CSS。为了解决这个问题,我发现this other post,如何添加自定义的CSS标签。但是,我并不是在寻找什么,也不知道如何将这些以适当的方式混合起来。

我的代码如下所示:

--- 
title: "R" 
output: html_document 
toc: yes 
runtime: shiny 
--- 

```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = TRUE) 
``` 
```{r results="asis"} 
cat("TOC { 
    position: fixed; 
    left: 0; 
    top: 0; 
    width: 200px; 
    height: 100%; 
    overflow:auto; 
} 
body { 
    max-width: 800px; 
    margin: auto; 
    margin-left:210px; 
    line-height: 20px; 
}") 
``` 

我觉得我失去了一些东西重要。提前致谢!

回答

0

在你first answe r的代码所示,您需要在您的YAML头添加这些,但你必须要小心的空间:

title: "cssTest" 
    output: 
    html_document: 
     css: custom.css 
     toc: yes 

然后,CSS文件应该是一个外部css文件。超出你的Rmd代码。在这里,它是与您的Rmd文件相同的目录中的文件,称为custom.css

+0

因此,不可能从Rmarkdown修改.css? –

+0

我不知道。你可以用'file = custom.css'来尝试'cat'。在运行Pandoc for HTML代码之前,这可能会首先运行R代码。 –

相关问题