Search code examples
textbackgroundlabelhighlightgraphviz

How do you change the font background color of just part of a GraphViz label?


I am trying to highlight a specific word/words in a GraphViz label. I know how to change the font color for individual text, but I can't figure out how to change the text background color instead. So, for example here, I would like to have this label with just the word "love" with a red background. Is this possible?

digraph G {

"A" -> "B" [label=<This is my label <br/> It has line breaks. I<FONT COLOR="Red">love</FONT>  background<br/>Colors.>]

}

Is this possible?


Solution

  • It requires creating an HTML table with one cell with desired background color.

    digraph G {
    
    "A" -> "B" [label=<This is my label <br/> It has line breaks. I <FONT COLOR="Red">love</FONT>  background<br/>Colors.>]
    
    C [label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
      <TR><TD COLSPAN="3">This is my label </TD></TR>
      <TR><TD>It has line breaks. I </TD><TD BGCOLOR="red">love</TD><TD>background</TD></TR>
      <TR><TD COLSPAN="3">Colors</TD></TR>  
      </TABLE>>]
    }
    

    Giving:
    enter image description here