当RMarkdown包含标签时,目录中的标题是空的?

问题描述 投票:0回答:1

当制作一个RMarkdown时 含片在目录中会出现一些额外的(空白)项目。

例子

这将生成下面的html文档

---
output: 
  html_document:
    toc: true 
---

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

# First Tabs {.tabset .tabset-fade .tabset-pills}

Text before tabs

## First tab

Content in first tab

## Second tab

Content in second tab

#


# here is another section
Some further content. 

enter image description here

一切都和预期的一样,只是TOC里有一行空白。

我试过的

我试着更换了 # 结束标签内容,用 </div> 如上所述 此处. 这将导致TOC正确填充,但(奇怪的是)导致标签后的内容左对齐(不知道为什么)。

为了便于复制,下面是代码和生成的HTML的截图。

---
output: 
  html_document:
    toc: true 
---

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

# First Tabs {.tabset .tabset-fade .tabset-pills}

Text before tabs

## First tab

Content in first tab

## Second tab

Content in second tab

</div>


# here is another section
Some further content. 

enter image description here

r r-markdown knitr
1个回答
2
投票

就像注释中写的那样。只要去掉单 #.如果你有以下问题,也有一个工作平台。

  • 使用TOC
  • 使用标签
  • 结束标签区域,在标签区域下有进一步的文字。

问题:通常使用 ## 来结束标签区域,但这将是TOC中的另一个头。

解决办法。## {.unlisted .unnumbered} 将从TOC中删除头部。

例子:将删除TOC中的页眉。

---
output: 
  html_document:
    toc: true 
---

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

## title {.tabset .tabset-fade}
content above tabbed region.

### tab 1 

tab content 1

### tab 2

tab content 2

## {.unlisted .unnumbered}

content below tabbed region

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.