Search code examples
rbookdown

Figure numbering in Bookdown disappears


I am trying to auto-number images in with Bookdown. It was working fine while my section headers were numbered, but when I remove the numbering in the sections, the figure numbers also disappear:

## This is a subheading {-}
```{r hp, fig.cap="Relationship between horsepower and miles per gallon", 
echo = FALSE}
plot(mtcars$hp, mtcars$mpg)
```

This is some text where I want to refer to the figure (Figure \@ref(fig:hp)).

Is it possible to have un-numbered subheadings, and still have the figures auto-number throughout the document (i.e., instead of it calling "Figure 1.1", "Figure 1.2", etc., you just get "Figure 1", "Figure 2")?


Solution

  • Section headings must be either numbered or unnumbered globally in the document. You didn't tell us which output format you were using, but usually it is an option named number_sections, which you can set to false, e.g.,

    output:
      bookdown::html_document2:
        number_sections: false
    

    Then figures will be numbered as Figure 1, 2, ..., N. See ?bookdown::html_document2 or the help page of the specific output format function you were using.