首页 > 解决方案 > 添加表格标题编号 R-Markdown

问题描述

我无法理解如何将图形标题编号表添加到 R-Markdown 中的表中。我正在使用bookdown并且一直在尝试理解文档的2.5 表部分。

它说,当您向函数添加标题时,kable它将自动标记为编号。但是,我只得到标签的“文本”部分而没有数字。

---
title: "test"
author: "x"
date: "February 20, 2019"
output: html_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>.

```{r libraries, echo=FALSE}
library(tidyverse, warn.conflicts = T)
library(kableExtra)
library(bookdown)
```


```{r example, echo=T}

head(pressure) %>%
  kable(caption = "Pressure",
        booktabs = T) %>%
  kable_styling(full_width = F)

```

非常感谢您帮助理解如何做到这一点。

标签: rr-markdownbookdownkable

解决方案


您没有使用bookdownrmarkdown::html_document()由于output标题。您需要将标题更改为

---
title: "test"
author: "x"
date: "February 20, 2019"
output: bookdown::html_document2
---

为了bookdown在单个文件项目中使用功能。对于实际书籍,最好让bookdown包为您设置骨架,例如通过 RStudio 插件。


推荐阅读