How to align text in Mermaid flowchart node?
Asked Answered
D

2

11

I would like to align text in a Mermaid flowchart node so the Thinkpad and iPad will line up. I tried to insert a \t before them but they just got rendered as text.

flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D["Laptop: Thinkpad\nTablet: iPad"]
    style D text-align:left
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]

enter image description here

Link to live editor

Dualistic answered 24/9, 2021 at 20:0 Comment(0)
F
9

I added a unicode space to line it up:

flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D["Laptop: Thinkpad\nTablet: iPad"]
style D text-align:left
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]

Image of Flowchart

Foretoken answered 5/2, 2022 at 20:1 Comment(0)
M
4

simple way: use space to fill it.

or if you just want to know how to print tab try use 	

Be careful! The graph does not work; please use the flowchart instead of it.

Example

<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.14.0/mermaid.min.js"></script>

<h2>Graph</h2>
<i>Do not use <code>graph</code> `\n` not work.</i>
<div class="mermaid">
graph TD
    A --> B["Laptop: Thinkpad\nTablet: iPad"]
</div>

<h2>flowchart</h2>
<div class="mermaid">
flowchart TD
    A --> B["Laptop: Thinkpad\nTablet&Tab;: iPad"] %% use TAB same as `&#9;`
    C --> D["Laptop: Thinkpad\nTablet : iPad"]     %% use space
    style B text-align:left
    style D text-align:left
</div>

Reference

Meader answered 18/2, 2022 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.