Search code examples
knitrcaptionbookdown

Bookdown caption in knitr include_graphics


I am writing a report with Bookdown and I am interested in reproducing a series of pictures horizontally with one single caption which describes them all. If I dont define the fig.cap I get the pictures correct as follows:

```{r, out.width = "33%",echo=FALSE}

knitr::include_graphics(rep(c("1.jpg","2.jpg","3.jpg"),1))

```

enter image description here

If instead I want to add a caption that describes all of the three pictures as follows I get the result below:

(ref:123) left: ...; centre ...; right ....

```{r, out.width = "33%",fig.cap='(ref:123)', echo=FALSE}

knitr::include_graphics(rep(c("one.jpg","two.jpg","three.jpg"),1))

```

enter image description here

What I would like instead is something like this:

enter image description here

Any help is much appreciated.


Solution

  • You should use the chunk option fig.show='hold'. See Figures 2.3 and 2.4 in the bookdown book for examples.