r - 将 {.tabset} 与 bookdown::bs4_book() 一起使用

标签 r r-markdown bookdown

我正在创建一个{ bookdown } 项目使用新的 bookdown::bs4_book()输出。但是,当我尝试使用 {.tabset} 向章节添加标签时,如 here 所述,不会生成选项卡。相反,文档以正常的线性布局呈现。

是否可以将 {.tabset}bookdown::bs4_book() 一起使用?

我在 this GitHub repo 中做了一个最小的 bs4_book() 项目,渲染的输出托管在这里:https://bs4-reprex.netlify.app/intro.html

这里是链接章节的原始 R Markdown 代码(也可以在 repo here 中找到)。

# Introduction {#intro}

You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \@ref(intro).
If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods).

## Figures and Tables {.tabset}

### Figures

Figures and tables with captions will be placed in `figure` and `table` environments, respectively.

```{r nice-fig, fig.cap='Here is a nice figure!', out.width='80%', fig.asp=.75, fig.align='center'}
par(mar = c(4, 4, .1, .1))
plot(pressure, type = 'b', pch = 19)
```

### Tables

Reference a figure by its code chunk label with the `fig:` prefix, e.g., see Figure \@ref(fig:nice-fig).
Similarly, you can reference tables generated from `knitr::kable()`, e.g., see Table \@ref(tab:nice-tab).

```{r nice-tab, tidy=FALSE}
knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE
)
```

##  {.unnumbered}

You can write citations, too.
For example, we are using the **bookdown** package [@R-bookdown] in this sample book, which was built on top of R Markdown and **knitr** [@xie2015].

最佳答案

来自 this response , .tabset 不是 {bookdown} 支持的功能。然而,这仍然可以通过使用 xaringanExtra::use_panelset() 来实现。

```{r panel-setup, include = FALSE}
xaringanExtra::use_panelset()
xaringanExtra::style_panelset(font_family = "inherit")
```

# Introduction {#intro}

You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \@ref(intro).
If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods).

## Figures and Tables {.panelset}

### Figures

Figures and tables with captions will be placed in `figure` and `table` environments, respectively.

```{r nice-fig, fig.cap='Here is a nice figure!', out.width='80%', fig.asp=.75, fig.align='center'}
par(mar = c(4, 4, .1, .1))
plot(pressure, type = 'b', pch = 19)
```

### Tables

Reference a figure by its code chunk label with the `fig:` prefix, e.g., see Figure \@ref(fig:nice-fig).
Similarly, you can reference tables generated from `knitr::kable()`, e.g., see Table \@ref(tab:nice-tab).

```{r nice-tab, tidy=FALSE}
knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE
)
```

##  {.unnumbered}

You can write citations, too.
For example, we are using the **bookdown** package [@R-bookdown] in this sample book, which was built on top of R Markdown and **knitr** [@xie2015].

{xaringanExtra} 尚未在 CRAN 上,但可以使用 remotes::install_github("gadenbuie/xaringanExtra") 从 GitHub 安装。另请注意,pansel 集不可移植到非 HTML bookdown 输出(例如 PDF),这就是 tabset 在 bookdown 中不受本地支持的原因。

关于r - 将 {.tabset} 与 bookdown::bs4_book() 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65724569/

相关文章:

r - 使用 R-markdown knitr hooks 自定义 HTML 报告中的表格格式

r - 在 RStudio 中编织时向 df_print 传递任意函数

rstudio - 将 pandoc 从 1.19 更新到 2.4 后,R markdown pandoc 文档转换失败,错误 1

css - 如何在 knitr::kable 中连续的表之间保留一些空间?

r - 子集 data.table 的速度以奇怪的方式取决于特定的键值?

r - 删除具有nan值的行

r - 如何提供(逻辑)运算符作为函数的参数

r - 你如何用赋值运算符结束管道?

r - 如何使用 Bookdown 更改单个文档中的标题标签名称?

r - 带有特定 latex 模板的书本