I use the following code to get consistent figure caption numbers when producing HTML and PDF from the same source:
.format <- knitr::opts_knit$get("rmarkdown.pandoc.to")
.tag <- function(N, cap ) ifelse(.format == "html",
paste("Figure ", N, ": ", cap, sep = ""),
cap)
If preceding text does not leave a blank line, the captions are correct in HTML but not in PDF
x = seq(0, 2*pi, length = 100)
plot(x, sin(x))
But it works with a blank line.
plot(x, sin(x))