Why figure numbers with two digits separated by dot are shown only in html_document2?

不想你离开。 提交于 2020-01-14 05:53:09

问题


Here is simple RMarkdown document with two sections and two images.

---
output:
  bookdown::html_document2: default
  bookdown::word_document2: default
  bookdown::pdf_document2: default
---

\newpage

# Part 1

Part 1 starts here. See Figure \@ref(fig:fig1-1) 

![(\#fig:fig1-1) expected to be Figure 1.1.](/usr/lib/rstudio/www/images/rstudio.png)

# Part 2

Part 2 starts here. See Figure \@ref(fig:fig2-1) 

![(\#fig:fig2-1) expected to be Figure 2.1.](/usr/lib/rstudio/www/images/rstudio.png)

I expect that two images will render with Knit to the following numbering - first is Figure 1.1, second is Figure 2.1. But I get this rendering only in html_document2 (see image below):

I use latest RStudio 1.1.414 with latest bookdown from Git (38efc82). I have two questions here:

  1. Why I don't have Figure 1.1 and Figure 2.1 in Word or PDF?
  2. How can I get Figure 1.1 and Figure 2.1 in Word or PDF?

回答1:


I can only address PDF output via LaTeX. By default the LaTeX documentclass article is used which uses continuous figure numbering. If your document is so long that it makes sense to number the figures within each top-level section, then you might want to use report or book instead, e.g.:

---
documentclass: book
output:
  bookdown::pdf_document2: default
  bookdown::word_document2: default
  bookdown::html_document2: default
---

Alternatively you can use some LaTeX package to change the formatting of figure numbers, e.g.:

---
header-includes:
  \usepackage{chngcntr}
  \counterwithin{figure}{section}
output:
  bookdown::pdf_document2: default
  bookdown::word_document2: default
  bookdown::html_document2: default
---

An alternative would be the \numberwithin command from amsmath in case you are using that package anyway.



来源:https://stackoverflow.com/questions/48254248/why-figure-numbers-with-two-digits-separated-by-dot-are-shown-only-in-html-docum

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