rpdflatexquartofigcaption

Align figure captions left in R quarto - knitting to PDF


I simply want the caption for my figures aligned left, rather than centre as the default is set.

How do I achieve this?

---
title: "Figure Caption Test"
format: pdf
---

```{r}
#| label: fig-test
#| fig-cap: "This is a test caption"

plot(rnorm(100))
```

See @fig-test.

Solution

  • Use \captionsetup from the caption package. Since quarto loads the caption package automatically, just tweak the options through the \captionsetup command.

    So to align the caption to left, you need to use justification=raggedright1. Also, use singlelinecheck=false so that caption gets left-aligned even if it is a one-line caption 2.

    ---
    title: "Figure Caption Test"
    format: pdf
    include-before-body:
      - text: |
          \captionsetup{justification=raggedright,singlelinecheck=false}
    ---
    
    ```{r}
    #| label: fig-test
    #| fig-cap: "This is a test caption"
    
    plot(rnorm(100))
    ```
    
    See @fig-test.
    

    rendered output with left aligned figure caption


    1 See section 2.2 page 8 of the caption package documentation for details

    2 see page 9 for details.