Search code examples
rpdfquartomermaid

Center mermaid in pdf Quarto


I would like to center a mermaid graph in pdf Quarto document. I tried using %%| fig-align in the code chunk, but this doesn't work. Here is some reproducible code:

---
title: "Center mermaid in pdf"
format: pdf
---

How to center a mermaid graph in pdf Quarto?

```{mermaid}
%%| fig-align: center
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
```

Output:

enter image description here

As you can see the graph is not centered in the document. So I was wondering if anyone knows how to center a mermaid graph in pdf Quarto? I'm using Quarto v1.4.


Solution

  • Once the %%| label: argument is set to fig-SOMETHING then the fig-align argument works properly.

    ---
    title: "Center mermaid in pdf"
    format: pdf
    ---
    
    How to center a mermaid graph in pdf Quarto?
    
    
    ```{mermaid}
    %%| label: fig-figure
    %%| fig-align: center
    flowchart LR
      A[Hard edge] --> B(Round edge)
      B --> C{Decision}
    ```
    
    

    Output:

    enter image description here

    My guess is that quarto needs to know that the chunk is producing a figure for other figure arguments to take effect. By including %%| label: fig-figure quarto then will process fig-align arguments.