5

I understood that using fig.scap should provide a short label for use with the table of figures, but it doesn't, it uses the long label. Any ideas? Rstudio Version 0.98.1091.

---
output:
  pdf_document:
    fig_caption: yes
---

\listoffigures


```{r, fig.cap="long caption",fig.scap="short"}
plot(1:4)
```
Steve Powell
  • 1,646
  • 16
  • 26

1 Answers1

5

This option was originally designed for .Rnw documents only. It does not apply to .Rmd documents. However, you can trigger LaTeX output for plots in R Markdown by specifying any of the chunk options out.width, out.height, and fig.align. For example,

---
graphics: yes
output:
  pdf_document:
    fig_caption: yes
---

\listoffigures


```{r, fig.cap="long caption", fig.scap="short", fig.align='center'}
plot(1:4)
```

Note you need knitr >= 1.8 (currently on CRAN) and Pandoc >= 1.13.1 (see comments below). The YAML metadata graphics: yes makes sure Pandoc is aware of graphics output in the document (it is too technical to explain here).


Update: With knitr >= v1.26.4, no special treatment (such as fig.align = 'center') is needed; using fig.scap will generate the correct LaTeX output. Since someone else has asked the same question again, I just decided to fix the issue on Github, and you will need

remotes::install_github('yihui/knitr')
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Trying exactly your code I get no caption but the latex commands are printed instead. The .tex file has this: \textbackslash{}begin\{figure\} \includegraphics[width=6in]{kill_files/figure-latex/unnamed-chunk-1-1} \textbackslash{}caption{[}short{]}\{long caption\label{fig:unnamed-chunk-1}\} \textbackslash{}end\{figure\} – Steve Powell Dec 02 '14 at 18:05
  • @StevePowell Sorry, I forgot to mention this requires Pandoc >= 1.13.1; the version of Pandoc shipped with the current RStudio IDE has a bug. If you use Windows or Mac OS X, you can just install Pandoc by yourself and RStudio will pick up your newer version of Pandoc automatically. I do not want to mention it in the public, but the current RStudio daily build provides Pandoc 1.13.1, if you dare to try: http://www.rstudio.org/download/daily/desktop/ (Please do not spread the words :) – Yihui Xie Dec 02 '14 at 20:46
  • thanks but I *do* have pandoc 1.13.1 installed via cabal on ubuntu 14.04. My rstudio is Version 0.98.1091. I would love this to work because at the moment if you have long explanatory captions on your figures, which is good practice IMO, you can't have a table of figures ;-( – Steve Powell Dec 05 '14 at 08:22
  • @StevePowell Have you tried my example? Installing Pandoc via cabal alone may not be enough. You need to make sure `pandoc` and `pandoc-citeproc` are on your `PATH`. To verify you installed Pandoc 1.13.1 properly, put `cat(system('pandoc --version', intern=TRUE), sep = '\n')` in the R Markdown document, and see what the version number really is. BTW, it will be so much easier just to install the Rstudio daily build than building Pandoc from source, although I'm not saying the latter is bad (it is just that you need to be careful about more details). – Yihui Xie Dec 07 '14 at 03:09
  • Yes, cat(system('pandoc --version', intern=TRUE), sep = '\n') printed a lower version, and yes the daily build now works. thanks. – Steve Powell Dec 08 '14 at 11:37