Quarto PDF: Adjust margins of captions in SUB-figures of figures

254 views Asked by At

I'm using Quarto and rendering to PDF. I have figures with sub-figures. The captions of the sub-figures are lengthy (many words). The problem is that the sub-figure captions are not separated in the PDF. Here's an illustration of the problem; notice that there is no separation (white space) between the captions of the sub-figures: illustration of problem

I have tried using LaTeX commands such as \captionsetup{width=0.9\textwidth} but that only affects the main caption under both sub-figures and does not affect the sub-figure captions.

Below I include the full contents of minimal example.

---
title: "Test of long captions in two sub-figures"
format:
  pdf:
    documentclass: article 
    papersize: letter
    geometry:
      - top=1.75in
      - bottom=1.75in
      - left=1.75in
      - right=1.75in
  html:
    theme: default
---

\captionsetup{width=0.9\textwidth}

```{r include=FALSE, echo=FALSE, message=FALSE}
# Make dummy image
png("DummyFigure.png")
plot( c(0,1) , c(0,10) , xlim=c(0,1) , ylim=c(0,10) , type="b" )
dev.off()
```

::: {#fig-TheFigure layout-nrow="1" layout-ncol="2"}
![**Here is the first subfigure caption.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.](DummyFigure.png){#fig-panelA width="200px"}

![**Here is the second subfigure caption.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.](DummyFigure.png){#fig-panelB width="200px"}

**Here is the main caption below both subfigures.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
:::

**This is the main document text. @fig-TheFigure shows two subfigures with long captions, and an overall captions beneath them. *I want the subfigure captions to be separated, not bumping into each other as they are here.* As one attempt, before the figure I inserted inline \LaTeX\ code: `\captionsetup{width=0.9\textwidth}`. Notice that the main caption has the reduced width, but not the subfigure captions.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
2

There are 2 answers

3
shafee On BEST ANSWER

You can use the command \captionsetup for subfigure to control the subcaptions. You can either use \captionsetup[subfigure]{margin=15pt} or \captionsetup[subfigure]{width=0.8\textwidth} to adjust the margins between the subcaptions.

---
title: "Test of long captions in two sub-figures"
format:
  pdf:
    documentclass: article 
    papersize: letter
    geometry:
      - top=1.75in
      - bottom=1.75in
      - left=1.75in
      - right=1.75in
    include-before-body: 
      text: |
        \captionsetup[subfigure]{margin=15pt}
  html:
    theme: default
---


```{r include=FALSE, echo=FALSE, message=FALSE}
# Make dummy image
png("DummyFigure.png")
plot( c(0,1) , c(0,10) , xlim=c(0,1) , ylim=c(0,10) , type="b" )
dev.off()
```

::: {#fig-TheFigure layout-ncol=2}

![**Here is the first subfigure caption.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.](DummyFigure.png){#fig-panelA width="200px"}

![**Here is the second subfigure caption.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.](DummyFigure.png){#fig-panelB width="200px"}

**Here is the main caption below both subfigures.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
:::

**This is the main document text. @fig-TheFigure shows two subfigures with long captions, and an overall captions beneath them. *I want the subfigure captions to be separated, not bumping into each other as they are here.* As one attempt, before the figure I inserted inline \LaTeX\ code: `\captionsetup{width=0.9\textwidth}`. Notice that the main caption has the reduced width, but not the subfigure captions.** Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Figures with margin adjusted subcaptions

0
John K. Kruschke On

After extensive searching and chasing down rabbit holes, I found this as one solution. Instead of

::: {#fig-TheFigure layout-ncol="2"}

use

::: {#fig-TheFigure layout="[10,-1,10]"}

The negative number indicates blank space between subfigures. Huh.

If there is another solution, I'm interested to learn about.