[Tex/LaTex] Unbalanced binary tree with forest


How can one draw an unbalanced binary tree – with missing nodes using the forest package?

Best Answer

There are various things you might mean by 'missing nodes'. A Minimal Working Example of the kind of tree you have, together with an explanation of how you wish to adapt it would be invaluable.

The following example shows three things you might have in mind:

Missing nodes

Node 2 is missing in a first sense: the branch simply continues without stopping to make the node. This creates an 'unbalanced' tree - the angles of the left and right branches are different.

  • This effect is achieved by altering the distance of node 4's level using l*=2 which doubles it.

Node 6 is missing in a second sense: it is simply empty. It is treated in every way as a proper node but there is no content.

  • This is straightforward - {} just provides empty content.

Node 9 is missing in a third sense: it causes a gap in the entire structure of branches and nodes. This isolates its children, 17 and 18 from the remainder of the tree.

  • This uses .phantom style demonstrated in NightRa's answer.

The code:


  [1, for tree=draw
    [4, l*=2
Related Question