4

I am visualising the changes of a tree between two different points in time and have come up with this so far:

\documentclass[12pt,paper=a4]{scrartcl}
\usepackage{forest}

\begin{document}
\begin{forest}
  for tree={
    circle,
    draw,
    minimum size = 1pt
    % font=\tiny
  }
  [, phantom, for children={fit=band}, s sep'+=60pt
    [,
      [,
        [
          []
          []
        ]
        []
      ]
      [,
        []
        []
      ]
      [,
        []
        [,name=left
          []
          []
        ]
      ]
    ]
    [,
      [,
        [,name=right
          []
          []
        ]
        []
      ]
      [
          [,
            []
            []
          ]
          [,
            []
            [
              []
              []
            ]
          ]
        ]
    ]
  ]
  \draw[-latex,double] (left) to (right);
\end{forest}

\end{document}

which produces the following output:

Current output

This is alright, but I would prefer for it to look more like this:

Desired result

So far all experiments with adding additional nodes have been unsuccessful. Adding outer sep for the nodes looks weird because it also adds the padding towards the regular edges of the tree.

Unrelated, but also interesting: can I make the tree nodes smaller than they are now? I know about minimum size, but would be interested in maximum size or something similar.

  • I would draw them as separate trees, I think. I don't see any gain from messing around with a phantom root in this case. – cfr Jan 20 '18 at 2:07
  • It was my first time using "forest", so I just googled to see what would be the fastest and easiest way to get this done, and copied boilerplate together from different SE answers - I saw your name around quite a lot yesterday! I'm satisfied with the solution, for now. It does what I want it to do. Do you mind posting your version, so that I can see how more experienced people would go about this? – fsperrle Jan 20 '18 at 9:04
  • There's nothing wrong with this. It just seems unnecessarily complicated. If you need the two trees to influence each other, a phantom root works nicely. (For example, if you want to keep the levels of the trees aligned, even if the nodes are different sizes, or you want to draw connections between points within the trees, as opposed to a connection between the two trees as wholes.) – cfr Jan 21 '18 at 0:02
4

For a shorter arrow, the simplest solution is to use tikz's shorten keys.

To make the circles smaller, use inner sep — the nodes are empty anyway. Probably, you will then also want to adjust forest's l sep, l and s sep.

(Below, I also changed double to very thick.)

\documentclass[12pt,paper=a4]{scrartcl}
\usepackage{forest}

\begin{document}

\begin{forest}
  for tree={
    circle,
    draw,
    inner sep=1pt,
    l sep=5mm,
    l=5mm,
    s sep=2mm,
  }
  [, phantom, for children={fit=band}, s sep'+=60pt
    [,
      [,
        [
          []
          []
        ]
        []
      ]
      [,
        []
        []
      ]
      [,
        []
        [,name=left
          []
          []
        ]
      ]
    ]
    [,
      [,
        [,name=right
          []
          []
        ]
        []
      ]
      [
          [,
            []
            []
          ]
          [,
            []
            [
              []
              []
            ]
          ]
        ]
    ]
  ]
  \draw[-latex,very thick,shorten <=5mm,shorten >=5mm] (left) to (right);
\end{forest}

\end{document}

shorter, thicker arrow; smaller circles

  • (+1) But I would be inclined to draw the trees separately. I don't see much benefit from mucking about with a phantom root here. (I know that wasn't the question.) – cfr Jan 20 '18 at 2:09
1

As requested, here's a way to do it without messing around with the phantom root. Use baseline for whichever of each tree's nodes you want aligned with the arrow.

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{%
  my tree/.style={
    for tree={
      circle,
      draw,
      inner sep=1pt,
      l sep'=5mm,
      l'=5mm,
      s sep'=2mm,
    },
  }
}
\begin{document}
\begin{forest}
  my tree,
    [,
      [,
        [, baseline
          []
          []
        ]
        []
      ]
      [,
        []
        []
      ]
      [,
        []
        [
          []
          []
        ]
      ]
    ]
\end{forest}
\begin{tikzpicture}
  \draw [-latex,very thick] (0,0) -- +(60pt,0);
\end{tikzpicture}
\begin{forest}
  my tree
    [,
      [,
        [, baseline
          []
          []
        ]
        []
      ]
      [
          [,
            []
            []
          ]
          [,
            []
            [
              []
              []
            ]
          ]
        ]
    ]
\end{forest}
\end{document}

aligned trees with connecting arrow in 3 parts

  • thank you! +1 for baseline, now it makes much more sense in my head. – fsperrle Jan 24 '18 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.