Home > Blockchain >  Reference parameter in figure caption with Quarto
Reference parameter in figure caption with Quarto

Time:11-30

Is there a way to reference a parameter in a Quarto figure or table caption? In the example below, I am able to reference my input parameter txt in a regular text block, but not in a figure caption. In the figure caption, only the raw text is displayed:

---
title: "example"
format: html
params: 
  txt: "example"
---

## I can reference it in text
Here I can reference an input parameter: `r params$txt`

```{r}
#| label: fig-example
#| fig-cap: "Example: I cannot reference a parameter using `r params$txt` or params$txt." 
plot(1:10, 1:10)
```

CodePudding user response:

Try with !expr

   ```{r}
   #| label: fig-example
   #| fig-cap: !expr params$txt
   plot(1:10, 1:10)
    ```

-output

enter image description here


If we need to add some text, either paste or use glue

#| fig-cap: !expr glue::glue("This should be {params$txt}")
  • Related