问题
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:
- Why I don't have Figure 1.1 and Figure 2.1 in Word or PDF?
- 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