4

When using bookdown (single document), if I set both section_numbering = 'yes' and fig_caption = 'yes', the figures are numbered X.2 (where X is the section number). If section_number = 'no', the figures are numbered sequentially (Fig 1, 2 ...), but sections numbers are lost.

Is there a way to get figures numbered sequentially without losing the section numbers? In the example below, I would like to have both the sections figures numbered as 1 and 2.

Thank you.

---
output: 
bookdown::html_document2: 
  fig_caption: yes
  number_sections: yes
---
# header 1
Reference example: \@ref(fig:plotcars):
```{r plotcars, fig.cap = "A car plot"}
plot(cars)
```
# header 2
Reference example: \@ref(fig:plotcars2):
```{r plotcars2, fig.cap = "A car plot"}
plot(cars)
```
Phil
  • 7,287
  • 3
  • 36
  • 66
  • I am not exactly sure, but there's a nice post [https://stackoverflow.com/questions/51945079/how-to-change-the-figure-caption-format-in-bookdown](https://stackoverflow.com/questions/51945079/how-to-change-the-figure-caption-format-in-bookdown) on figure caption formatting that might be useful. – DaveArmstrong Sep 11 '20 at 15:54
  • 1
    Sorry, but this is currently not possible. Numbering sections implies that figures are numbered along with sections. If you really want to separate the two numbering systems, you may file an issue to the Github repo. Thanks! – Yihui Xie Sep 11 '20 at 17:39
  • Thank you for your reply and your great software. I will fill an issue then. – Hilaire Drouineau Sep 12 '20 at 16:43

1 Answers1

2

I just added a new argument global_numbering to the dev version of bookdown. You can test the dev version via

remotes::install_github('rstudio/bookdown')

Example:

---
output: 
  bookdown::html_document2: 
    fig_caption: true
    number_sections: true
    global_numbering: true
---

# header 1

Reference example: \@ref(fig:plotcars):

```{r plotcars, fig.cap = "A car plot"}
plot(cars)
```

# header 2

Reference example: \@ref(fig:plotcars2):

```{r plotcars2, fig.cap = "A car plot"}
plot(cars)
```
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419