Include fig.cap when referencing a figure in Bookdown or Blogdown

Hongtao Hao / 2020-08-21

Yihui documented figure referencing very well. There is only one thing I need to add: do remember to add a figure caption if you want to reference it.

For example, if we have a chunk label without a figure caption:


We cannot reference it: Figure ??.

This is because without a figure caption, the figure won’t be numbered. Without a number, the figure cannot be referenced.

Simply adding a figure caption solves the problem:


Figure 1: temperature-pressure

Now we can reference it: Figure 1

Last modified on 2021-10-07