# Horizontal Legend Creation

**URL:** <https://forum.graphviz.org/t/horizontal-legend-creation/785>\
**Category:** Help\
**Created:** [August 24, 2021, 6:22am UTC](https://forum.graphviz.org/t/horizontal-legend-creation/785 "2021-08-24T06:22:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sikpande](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@sikpande](https://forum.graphviz.org/u/sikpande)\
**Post date:** [August 24, 2021, 6:22am UTC](https://forum.graphviz.org/t/horizontal-legend-creation/785/1 "2021-08-24T06:22:28Z")

</div>

Hi ,  
I want to draw a legend horizontally to the top of a graph produced by graphviz.

I have written this code  
diagraph\_obj.attr(‘graph’, labelloc=“t”, label=’’’\<

```
        <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4" VALIGN="TOP" HEIGHT="2.0">
         <TR>
          <TD COLSPAN="2"><B>Device Gen Info</B></TD>
         </TR>
         <TR>
          <TD> <FONT POINT-SIZE="10.0">Gen5</FONT> </TD>
          <TD BGCOLOR="ORANGE"> </TD>
         </TR>
         <TR>
          <TD>Gen4</TD>
          <TD BGCOLOR="GREEN"></TD>
         </TR>
         <TR>
          <TD>Gen3</TD>
          <TD BGCOLOR="YELLOW"></TD>
         </TR>
         <TR>
          <TD>Gen2</TD>
          <TD BGCOLOR="BROWN"></TD>
         </TR>
         <TR>
          <TD>Default</TD>
          <TD BGCOLOR="VIOLET"></TD>
         </TR>
         <TR>
          <TD>Timed Out</TD>
          <TD BGCOLOR="RED"></TD>
         </TR>
         <TR>
          <TD>Access Point</TD>
          <TD>Triangle</TD>
         </TR>
         <TR>
          <TD>Relay</TD>
          <TD>Parallelogram</TD>
         </TR>
          <TR>
          <TD>Bridge</TD>
          <TD>Daimond</TD>
         </TR>
          <TR>
          <TD>High Priority Access Point</TD>
          <TD>DoubleCircle</TD>
         </TR>
          <TR>
          <TD>High Priority End Point</TD>
          <TD>Trippleoctagon</TD>
         </TR>
          <TR>
          <TD>High Priority Relay</TD>
          <TD>House</TD>
         </TR>
          <TR>
          <TD>NIC</TD>
          <TD>Pentagon</TD>
         </TR>
          <TR>
          <TD>LCS</TD>
          <TD>Trapezium</TD>
         </TR>
          <TR>
          <TD>STL</TD>
          <TD>Star</TD>
         </TR>
          <TR>
          <TD>IOTR</TD>
          <TD>Circle</TD>
         </TR>
          <TR>
          <TD>Default</TD>
          <TD>Rectangle</TD>
         </TR>
          <TR>
          <TD>Timed Out</TD>
          <TD>Septagon</TD>
         </TR>
        </TABLE>
         >''')

```

And the legend drawn from the code snippet is vertical but I want to draw it horizontally with automatic fixed legend size.

Any help or guidance is highly appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [August 24, 2021, 5:11pm UTC](https://forum.graphviz.org/t/horizontal-legend-creation/785/2 "2021-08-24T17:11:36Z")

</div>

Is this what you are after? (I’m not sure what “_automatic fixed legend size_” means)

```auto
digraph LL {
  graph [labelloc=t, label=<
        <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4" VALIGN="TOP" HEIGHT="2.0">
         <TR>
          <TD COLSPAN="99"><B>Device Gen Info</B></TD>
         </TR>

         <TR>
          <TD> <FONT POINT-SIZE="10.0">Gen5</FONT> </TD>
          <TD>Gen4</TD>
          <TD>Gen3</TD>
          <TD>Gen2</TD>
          <TD>Default</TD>
          <TD>Timed Out</TD>
          <TD>Access Point</TD>
          <TD>Relay</TD>
          <TD>Bridge</TD>
          <TD>High Priority Access Point</TD>
          <TD>High Priority End Point</TD>
          <TD>High Priority Relay</TD>
          <TD>NIC</TD>
          <TD>LCS</TD>	  
          <TD>STL</TD>
          <TD>IOTR</TD>
          <TD>Default</TD>
          <TD>Timed Out</TD>

         </TR>
         <TR>
          <TD BGCOLOR="ORANGE"> </TD>
          <TD BGCOLOR="GREEN"></TD>
          <TD BGCOLOR="YELLOW"></TD>
          <TD BGCOLOR="BROWN"></TD>
          <TD BGCOLOR="VIOLET"></TD>
          <TD BGCOLOR="RED"></TD>
          <TD>Triangle</TD>
          <TD>Parallelogram</TD>
          <TD>Diamond</TD>
          <TD>DoubleCircle</TD>
          <TD>Trippleoctagon</TD>
          <TD>House</TD>
          <TD>Pentagon</TD>
          <TD>Trapezium</TD>
          <TD>Star</TD>
          <TD>Circle</TD>
          <TD>Rectangle</TD>

          <TD>Septagon</TD>
         </TR>
        </TABLE>>]

  // add a cluster to create margin between legend & actual graph
  subgraph clusterAll{
    graph[label="" peripheries=0] // do not duplicate graph legend
    a ->b ->c
  }
}

```

Giving:

 ![fixLegend1](https://global.discourse-cdn.com/graphviz/original/1X/f20365a6fb4b058adcf82228f59148786d83ad4c.png)

p.s. more on Legends: [Adding key or legend?](https://forum.graphviz.org/t/adding-key-or-legend/351)  
p.p.s. You can replace your textual descriptions (e.g. House) with images  
`<TD><IMG SCALE="TRUE" SRC="image_dir/noLeft.png"/></TD>`
