首页 > 解决方案 > R Markdown pdf_document2 PDF图形和表格编号按部分

问题描述

我想pdf_document2在 R Markdown 中生成一个 PDF 文档,其中的表格和数字根据它们的节号进行标记。例如,第 2 节中的第一个图是图 2.1。我可以用html_document2但不能用pdf_document2.

请参阅下面的代码,了解我编写的代码。现在,代码生成连续的图形编号(图 1、2、3、4),而不是图 1.1、1.2、2.1、2.2。


title: "Testing Section Numbers"
author: "Authors"
date: "January 2019"
output:
  bookdown::pdf_document2:
    fig_caption: yes
    latex_engine: xelatex
    number_sections: true
    toc: yes
    toc_depth: 2
editor_options:
  chunk_output_type: console
link-citations: yes
linkcolor: blue
subparagraph: yes
citecolor: blue
urlcolor: blue
---

# R Markdown

```{r pressure1, echo=FALSE, fig.cap="This is my plot"}
plot(pressure)
```

```{r pressure2, echo=FALSE, fig.cap="This is my plot"}
plot(pressure)
```

# Including Plots

You can also embed plots, for example:

```{r pressure3, echo=FALSE, fig.cap="This is my plot"}
plot(pressure)
```

```{r pressure4, echo=FALSE, fig.cap="This is my plot"}
plot(pressure)
```

标签: latexr-markdownbookdown

解决方案


笨拙的解决方案是在标题中添加一些 LaTeX 命令:

header-includes:
  \let\counterwithout\relax
  \let\counterwithin\relax
  \usepackage{chngcntr}
  \counterwithin{figure}{section}

推荐阅读