R Markdown adds a figure ID when generating figures via R, but not for pure Markdown images. In this case, you can add an ID yourself:
![Caption with spaces](path/to/pictures.png){#fig:caption-with-spaces}
The id can be chosen freely, but should start with fig:
.
If you'd like a keep everything in pure Markdown, but don't want to add identifiers manually, you can use a pandoc Lua filter:
local stringify = (require 'pandoc.utils').stringify
function Image (img)
if img.identifier == '' then
img.identifier = 'fig:' .. stringify(img.caption):gsub('%s', '-'):lower()
return img
end
end
Use by adding a pandoc_args
parameter to your output settings:
output:
bookdown::pdf_document2:
pandoc_args: ['--lua-filter', 'auto-image-ids.lua']