2017-05-08 34 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代碼。 –

相關問題