Mermaid Entity-Relationship diagram in top-down layout
06:05 24 Nov 2023

Consider the following mermaid diagram:

erDiagram
  CLIENT {}
  ACCOUNT {}
  PRODUCT {}
  ADDRESS {}
  INVESTMENT {}
  REPORT {}

  
  CLIENT ||--o{ ACCOUNT : account_fkey
  CLIENT ||--o{ PRODUCT : product_fkey
  CLIENT ||--o{ ADDRESS : address_fkey
  CLIENT ||--o{ INVESTMENT : investment_fkey
  CLIENT ||--o{ REPORT : report_fkey

Mermaid compiles this syntax into a "left-right" layout (apparently the default):

enter image description here

It is easy to see how this layout may rapidly become unusable, both in web pages as well as in documents. With other types of diagrams it is possible to set the layout to "top-down" by appending the characters TD to the diagram type identifier. For the diagram above this would be:

erDiagram TD 
  CLIENT {}
  ACCOUNT {}
  PRODUCT {}
  ADDRESS {}
  INVESTMENT {}
  REPORT {}

  
  CLIENT ||--o{ ACCOUNT : account_fkey
  CLIENT ||--o{ PRODUCT : product_fkey
  CLIENT ||--o{ ADDRESS : address_fkey
  CLIENT ||--o{ INVESTMENT : investment_fkey
  CLIENT ||--o{ REPORT : report_fkey

However, mermaid instead interprets the layout instruction as an additional entity in the diagram:

enter image description here

Then, how can the layout be set in a mermaid ER diagram?

entity-relationship erd mermaid