R Markdown pdf_document2 PDF图形和表格编号(按部分) [英] R Markdown pdf_document2 PDF figure and table numbers by section

查看:71
本文介绍了R Markdown pdf_document2 PDF图形和表格编号(按部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R Markdown中生成一个 pdf_document2 PDF文档,其中表格和图形根据其节号进行标记.例如,第2节中的第一个图将是图2.1.我可以使用 html_document2 来做到这一点,但不能使用 pdf_document2 来做到这一点.

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.

有关我编写的代码,请参见下文.现在,代码将生成连续的图形编号(图1、2、3、4),而不是图1.1、1.2、2.1、2.2.

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)
```

推荐答案

繁琐的解决方案是在标头中添加一些LaTeX命令:

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}

这篇关于R Markdown pdf_document2 PDF图形和表格编号(按部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆