首页 > 解决方案 > 选项卡中的多个块

问题描述

我希望在单个选项卡中包含示例 1 和示例 2,在另一个选项卡中包含示例 3。下面的代码在一个选项卡中显示所有内容。在我想要的输出中,sectionA 选项卡中的一些块和 sectionB 选项卡中的一些块。

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
    code_folding: show
    theme: united
    highlight: tango
    toc: true
    toc_float: true
    toc_depth: 3  # upto three depths of headings (specified by #, ## and ###)
---

```{r, echo=FALSE}
library(rmarkdown) #used for syntax highlighting in this document
```

## Sections {.tabset}

### Section A

# Example1
```{r, eval=FALSE}
plot(cars)
```
<details>
  <summary>Click for Output</summary>
    ```{r, echo=FALSE, eval=TRUE}
    plot(cars)
    ```
</details> 

### Section B

# Example2
```{r}
quantile(mtcars$mpg, probs = c(0.99))
```
## {-}

# Example3
```{r table}
knitr::kable(mtcars[1:5,, 1:5], caption = "A table caption")
``````

标签: rr-markdown

解决方案


如果我理解正确,您想要这些方面的东西吗?一旦你开始一个选项卡式的部分,你就不能随便扔掉子部分,但应该遵循特定的层次结构。如果您有一个选项卡部分 level ##,则 level 下的所有内容都###将成为选项卡。任何比这更深的东西都将成为所述选项卡中的标题。

## Sections {.tabset}

### Section A

#### Example1
```{r, eval=FALSE}
plot(cars)
```
<details>
  <summary>Click for Output</summary>
    ```{r, echo=FALSE, eval=TRUE}
    plot(cars)
    ```
</details> 


#### Example2
```{r}
quantile(mtcars$mpg, probs = c(0.99))
```

### Section B
#### Example3
```{r table}
knitr::kable(mtcars[1:5,, 1:5], caption = "A table caption")
``````

在此处输入图像描述


推荐阅读