How to make a figure caption in Rmarkdown?

rosannavh picture rosannavh · Jun 26, 2015 · Viewed 23.7k times · Source

I am thinking about writing my thesis with rmarkdown and latex. I'm getting the hang of how it all works, however, when I try to add a figure (not an R plot) to the text and render it to pdf, the caption and in-text reference dissappear.

This is the code snippet I use to add a figure:

---
title: "Untitled"
output: pdf_document
---

see figure \ref{fig1}.

![picture \label{fig1}](figure1.png)

This is what knitr creates:

This is what pandoc creates:

Question: How do I make figure captions and in-text references to those figures in Rmarkdown that will display when rendered to pdf?

OR

How do I tell pandoc what Rmarkdown is so it will render R code and plots?

Answer

Yihui Xie picture Yihui Xie · Jun 26, 2015

Please see the documentation of R Markdown for PDF output, and in particular, look for fig_caption. Figure captions are turned off by default in R Markdown, and you have to turn them on (fig_caption: true). You can also find this setting from the gear button on the toolbar of RStudio IDE.