Tit*_*anz 5 html css r knitr r-markdown
我正在尝试在 Rmarkdown 生成的 HTML 文档中添加目录。首先,我找到了这个答案,这似乎是一个简单的方法,在 HTML 文件中添加一个 CSS 文件,并使用以下代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
但我想从 Rmarkdown 修改 CSS。为了解决这个问题,我找到了另一个帖子,如何添加自定义 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;
}")
```
Run Code Online (Sandbox Code Playgroud)
我想我错过了一些重要的事情。提前致谢!
如第一个答案的代码所示,您需要将这些添加到 YAML 标头中,但需要小心空格:
title: "cssTest"
output:
html_document:
css: custom.css
toc: yes
Run Code Online (Sandbox Code Playgroud)
那么,css文件应该是外部css文件。超出您的 Rmd 代码。在这里,它是与 Rmd 文件位于同一目录中的一个文件,称为custom.css.
| 归档时间: |
|
| 查看次数: |
5197 次 |
| 最近记录: |