# Knitr and rmarkdown will not add figure captions to the output

I am writing a report on Rmarkdown and knitr using RStudio, and cannot find a way to get figure captions on my document. My code for the chunk where I try to plot is like:

```{r fig1,fig.width=4,fig.height=4,echo=FALSE,message=FALSE,include=TRUE,fig.cap="Caption"}

plot(rnorm(100,2),rnorm(100,8))
```

No caption is added to the pdf output, and a look at the intermediary latex file reveals that the figure environment is not created:

\includegraphics{./Untitled_files/figure-latex/fig.pdf}

Otherwise, the pdf document is created without any problems, it just misses the captions. I have read in the knitr manual and in many other questions about the topic that the chunk option fig.cap will add the figure environment. I tried to add the fig.env=TRUE option, as well, but the results are the same. Is this an issue with rmarkdown in rstudio only or is it that in general it will not work?

• How are you converting from .Rmd to .pdf? – Adam Liter Sep 19 '14 at 15:50
• Using knitr and pdfLaTex. Knitr produces a .tex file and pdfLaTex takes over from there, I suppose. – Kenji Sep 19 '14 at 16:45
• Calling knit() on an .Rmd file will produce .md output, though. How exactly are you going from .Rmd to a .tex file? – Adam Liter Sep 19 '14 at 16:56
• And knit2pdf() only works on .Rnw files and .Rrst files. – Adam Liter Sep 19 '14 at 17:04
• I use the built in functionality in RStudio. It works alright and outputs the PDF, it just fails to add a caption. – Kenji Sep 21 '14 at 11:26