Move figure captions to next page using bookdown?

42 Views Asked by At

I'm writing a report using bookdown and have a large figure that needs to be included, but its figure caption runs off the page when the file is knitted as a PDF document. To fix this, I need to put the caption on the next page so all the required information is included and the components of the figure are easily visible.

How can I put the caption of a figure onto the next page when the file is rendered into a PDF document?

Here is a reproducible example with some Lorem Ipsum text using the mtcars data set:

---
title: "Figure caption on next page"
author: "John Smith"
date: "`r Sys.Date()`"
output:
  bookdown::pdf_book:
    fig_caption: true
    latex_engine: xelatex
---

Please refer to Figure \@ref(fig:test-figure).

```{r load-library-data include = FALSE}
library(ggplot2)
str(mtcars)
```{r test-figure, fig.cap = "(ref:test)", fig.pos = "H", echo = FALSE}
ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point()

(ref:test) Can this caption go on the next page? Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt nisl leo, ac fringilla ligula ultricies id. Sed lobortis placerat condimentum. Duis vel magna eget purus eleifend sodales. Vivamus justo orci, pretium et sollicitudin ac, pellentesque sit amet neque. Proin viverra sapien a suscipit pharetra. Nullam eget mollis lorem, et facilisis sem. Donec tincidunt neque sollicitudin purus tristique rhoncus.

Any help and/or references to where I can find a solution will be greatly appreciated!

0

There are 0 best solutions below