How to make invisible nodes occupy space in graphviz?

13,130

Better late than never...

You probably left your dummy node empty (""). If you give it a reasonably sized label, it works fine:

graph Test 
{
    node[ shape = plaintext ];

    C [ label = "C", style = invis ];

    A -- B;
    A -- C [ style = invis ]; 
}

A good example to demonstrate that an MWE saves time and effort...

enter image description here

Share:
13,130

Related videos on Youtube

Fernando
Author by

Fernando

Updated on September 24, 2022

Comments

  • Fernando
    Fernando over 1 year

    I want to plot a binary tree using graphviz, and it is important that the left child of a node appear to the left (duh) of the right child. If there is no left child, I want an empty space on the left, to make it visually clear that the right child is the right child. I want to do the same if there is no right child (on the right there should be an empty space).

    For instance, I want something like:

    A                     A
      \     instead of    |
        B                 B
    

    I can make sure Graphviz will place the left child before the right by using ordering = "out", but if there is no left child, then the right child might appear right below its parent.

    If I add dummy nodes where a child is missing, I get the correct layout, but the dummy nodes are then on the picture (and I don't want them). I tried using style = "invis" for the dummy nodes and edges connecting to them, but then it is as if they didn't exist for graphviz. How can I get around this problem?

  • Prof.Chaos
    Prof.Chaos over 2 years
    Note that this only works if according to the layout B is already aligned on the right side of A, i.e., if the three nodes are aligned in a triangle shape. In this minimal example that's the case, but in others the right child might still be exactly below A, and B's brother might be on it's left. So making it invisible doesn't help.