New line in fig.cap

Hi,

My question is that is there a way to add a new line to a figures caption in rmd when creating a latex pdf file?

Thank you for your answer in advance,
Marcell

1 Like

Do you have an example of what you want to achieve exactly ?

Here is a small example of adding a linebreak in caption for pdf document. It implies using latex code in the figure caption and the caption tex package that allows that, so it is for PDF output only

Solution1 : requires escaping

---
title: Test
output: 
  pdf_document:
    keep_tex: true
    extra_dependencies: caption
---

```{r, fig.cap="caption \\linebreak with a new line"}
plot(1:10)
```

Solution2: based on bookdown format and text reference

---
title: Test
output: 
  bookdown::pdf_document2:
    keep_tex: true
    extra_dependencies: caption
---

(ref:test) A caption \linebreak with a new line

```{r, fig.cap= "(ref:test)"}
plot(1:10)
```

Also, you may be instered in this answer: https://stackoverflow.com/a/53854516/3436535
and more on subfigures: https://bookdown.org/yihui/rmarkdown-cookbook/latex-subfigure.html

Hi,

Solution1 was the one I looked for.
Thank you very much
Marcell

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.