Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Short caption fig.scap in knitr not working?

Tags:

r

latex

knitr

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)
```
like image 377
Steve Powell Avatar asked Dec 02 '14 13:12

Steve Powell


1 Answers

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')
like image 159
Yihui Xie Avatar answered Oct 13 '22 23:10

Yihui Xie