Aligning .dot Labels

Over the past few years I’ve been making heavy use of DOT, the Directed Graph programming language, using GraphViz for output. It’s basically a text format for building flowchart like diagrams (i.e. directed graphs). It’s a classic computer science thing; “Very Smart, Very Obtuse Syntax”.

I’d been running into a problem where I couldn’t get me labels to correctly left or right align. They’d always appear to align center. Even when I discovered there are three newline characters

  1. \n Newline, align center
  2. \l Newline, align left
  3. \r Newline, align right

I’d still get what looked like centered output. It turns out that, in dot, each line of a label can have a different alignment. So, adding a final \l to my labels fixed things.

NODE [
    label="This is a test \lof creating my lines\lin a non-centeredway\l"
]

I pass this into the internet group mind in the hope it saves someone else some time.

Originally published June 29, 2009