R Markdown pdf_document2 PDF figure and table numbers by section

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-17 14:09:55

问题


I want to generate a pdf_document2 PDF document in R Markdown where the tables and figures are labeled according to their section number. For instance, the first figure in Section 2 would be Figure 2.1. I can do that with html_document2 but not with pdf_document2.

See below for the code that I have written. Right now the code generates continuous Figure numbers (Figures 1, 2, 3, 4) instead of Figures 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)
```

回答1:


The kludgey solution is to add some LaTeX commands to the header:

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


来源:https://stackoverflow.com/questions/53863797/r-markdown-pdf-document2-pdf-figure-and-table-numbers-by-section

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!