【发布时间】:2014-07-20 08:55:26
【问题描述】:
我正在使用 RStudio 编写 markdown 文档,并希望在文档顶部添加目录 (TOC),以便用户可以单击相关部分进行阅读。 rpubs 上有一些相关的例子,但现在我似乎找不到它们。请注意,我不使用pandoc 并且对Rmd 和knitr 很陌生。有什么方法可以在不使用pandoc 的情况下添加 TOC?如果必须使用pandoc,那么哪些函数是相关的?
编辑
这是一个小示例页面:
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
Header 1
---------------
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
## Header 2
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
### Header 3
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
我尝试在 RStudio v 0.98.864 中运行它,它成功了!但遗憾的是它不适用于 0.98.501 和 0.98.507。我在 0.98.501 上写我的论文,在更新 RStudio 之后,我的一些分析没有奏效。所以,我恢复到 0.98.501。 我现在该怎么办?我真的想要 TOC,但又不会损害其他分析的输出。
【问题讨论】:
-
我相信 Rstudio 使用的 rmarkdown 包是 pandoc 的包装器,因此您应该能够传递相关选项。事实上,YAML front-matter 中的
toc: true应该这样做。 -
尝试缩进,遵循rmarkdown.rstudio.com 中的示例,如果其他一切都失败则更新 Rstudio
-
@umairdurrani 好的。该示例没有任何标题。你想在目录中出现什么?
-
感谢@baptiste,我也遇到了这个问题,但缩进可以正确解决。
-
在标题中正确缩进是关键
标签: r rstudio r-markdown