我正在尝试将以下 div 和类添加到 knitr 中的整个 Rmd 文件中:
<div class="container">
</div>
我使用 css 创建了容器类,如下所示:
.container {
box-shadow: 10px 10px 5px #888888;
width: 70%;
margin: 15em auto 5em;
margin-bottom:-9em;
margin-top:5em;
background: #FFF;
}
.container p {
padding-left: 14%;
padding-right: 10%;
text-indent : 1.25cm;
}
body {
background: #efefef;
}
我通常会使用 style.css 来添加它,但对于 MWE,我们会将它放在最后 MW Rmd 文件的主要文档正文中。我用
div
包裹了整个文档类(class)container
并获得此输出 HERE .注意标题 # Hello World
不作为标题处理? div
内没有任何内容标签被处理为 html。我可以通过在没有 div
的情况下运行 knitr 来解决这个问题容器,然后在稍后添加它,如下所示:( The HTML 和 The Rmd )。如何添加
div
标签直接添加到 Rmd 文件?<div class="container">
# Hello World
```{r setup, include=FALSE}
opts_chunk$set(cache=FALSE)
library(knitr); library(knitcitations);
```
<style>
.container {
box-shadow: 10px 10px 5px #888888;
width: 70%;
margin: 15em auto 5em;
margin-bottom:-9em;
margin-top:5em;
background: #FFF;
}
.container p {
padding-left: 14%;
padding-right: 10%;
text-indent : 1.25cm;
}
body {
background: #efefef;
}
</style>
</div>
最佳答案
使用自定义模板将 Rmd 包装在 <div class="container"></div>
中
<!DOCTYPE html>
<html>
<head>
<title>#!title#</title>
</head>
<div class="container">
#!html_output#
</div>
</html>
然后在编织的时候调用模板
knit2html('document.Rmd', template='template.html', title='Page title')
这样你也可以添加自定义
style.css
到模板
关于r - 在 knitr 中的所有文本周围添加 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20984985/