I am deeply convinced that Graphviz should not be used this way, but you can use HTML tags . achieve what you want:
digraph { Foo -> Bar -> Test; Foo -> Baz -> Test; { rank = sink; Legend [shape=none, margin=0, label=< <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR> <TD COLSPAN="2"><B>Legend</B></TD> </TR> <TR> <TD>Foo</TD> <TD><FONT COLOR="red">Foo</FONT></TD> </TR> <TR> <TD>Bar</TD> <TD BGCOLOR="RED"></TD> </TR> <TR> <TD>Baz</TD> <TD BGCOLOR="BLUE"></TD> </TR> <TR> <TD>Test</TD> <TD><IMG src="so.png" SCALE="False" /></TD> </TR> <TR> <TD>Test</TD> <TD CELLPADDING="4"> <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"> <TR> <TD BGCOLOR="Yellow"></TD> </TR> </TABLE> </TD> </TR> </TABLE> >]; } }
What it looks like:

Legends should be positioned like any other node (I used a satchel = shell to finish it) - you can play with its margin attribute for a fine - setting the position.
Edit
Without the use of labels for which it may be directed - I am not sure whether to completely exclude ranksep .
digraph { mindist=0; ranksep=0; nodesep=0; node[shape=box,margin="0,0",width=1, height=0.5]; edge [style=invis]; Legend[width=2]; Legend -> Foo; Legend -> FooValue; Foo -> Bar; FooValue -> BarValue Bar -> Baz; BarValue -> BazValue; edge [constraint=false]; Foo -> FooValue; Bar -> BarValue Baz -> BazValue; }
Result:

marapet Jan 20 2018-11-21T00: 00Z
source share