【问题标题】:RMarkdown: Floating TOC and TOC at beginningRMarkdown:开始浮动TOC和TOC
【发布时间】:2018-01-15 10:44:35
【问题描述】:

我想知道是否可以在文档开头有一个浮动目录和另一个目录。我目前的front-matter看起来是这样的:

---
title: "TEST"
author: brettljausn
date: January 15, 2018
output: 
  html_document:
    toc: true
    toc_float:
      toc_collapsed: true
    toc_depth: 3
    number_sections: true
    theme: lumen
---


# Rest of the sample document: --------

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# R Markdown

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>.

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 cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

我尝试添加另一个toc: true,但这只是给我一个错误消息。提前致谢!

【问题讨论】:

  • 这似乎有可能,但并不明显。你试过用 Javascript 吗?
  • @brettljausn 让我知道下面的答案是否对您有所帮助。谢谢。

标签: html r knitr r-markdown


【解决方案1】:

你只需要在 toc_float 前面加上 true:

---
title: "TEST"
output: 
  html_document:
  toc: true
  toc_float: true
  toc_collapsed: true
toc_depth: 3
number_sections: true
theme: lumen
---

另请注意,您的 rmarkdown 文件中有一条注释,该注释将被解释为标题:

示例文档的其余部分:--------

【讨论】:

  • 答案似乎对我不起作用:html开头只有一个浮动的toc,没有toc。
  • 您还需要注意 yaml 中的缩进: toc_depth 和 number_sections 需要缩进。以及 html_document 之后的所有内容(主题除外)都需要缩进更多。
【解决方案2】:

正如@j_5chneider 在最佳答案的评论中指出的那样,缩进不正确。不允许我编辑给定的答案,因此添加一个新答案以避免混淆。与@Dan 给出的答案相同,但缩进已修复。

---
title: "TEST"
output: 
  html_document:
    toc: true
    toc_float: true
    toc_collapsed: true
    toc_depth: 3
    number_sections: true
    theme: lumen
---

【讨论】:

    猜你喜欢
    • 2017-04-22
    • 1970-01-01
    • 2021-07-23
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    相关资源
    最近更新 更多