当 RMarkdown 包含标签时,table 内容中的空标题?

Empty headings in table of contents when RMarkdown contains tabs?

制作 RMarkdown 时,一些额外的(空白)项目出现在 table 的内容中。

例子

这会生成下面的 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. 

除了 TOC 中有一个空行外,一切都符合预期。

我试过的

我尝试用 </div> 替换结束选项卡式内容的 #,如 所述。这会导致 TOC 正确填充,但(奇怪地)导致选项卡后的内容变为 left-align(不知道为什么)

为了便于重现,这里是代码和生成的屏幕截图 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. 

如评论中所写:只需删除单个 #。 还有一个workaorund,如果你有以下问题

  • 使用目录
  • 使用制表符
  • 结束标签区域,标签区域下方有更多文本

问题:通常使用 ## 结束标签区域,但这将是 TOC

中的另一个 header

解决方案:## {.unlisted .unnumbered} 将从目录中删除 header。

示例:

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