2

I would like to "animate" a growing tree. This means that the nodes and edges in trees (a)-(c) should be aligned like the final tree. Falsely Aligned

Unfortunately I couldn't figure out how to do this with the forest package or in general (other than drawing everything "by hand" with tikz).

The code used for generating the falsely aligned picture is:

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage[linguistics]{forest}
\begin{document}
\begin{figure}
\centering
\subcaptionbox[Tree]{
    Tree
    \label{subfig:sublabel1}%
}
[0.3\textwidth]
{%
\begin{forest}for tree={inner sep=0pt,outer sep=0pt, s sep=(2-level)*2mm, l=(8-level*level*level)*0.1mm}
  [,s sep=30
    [1
      [1]
    ]
  ]
\end{forest}}
\hspace{0.1\textwidth}
\subcaptionbox[Tree]{
    Tree
    \label{subfig:sublabel1}%
}
[0.3\textwidth]{
\begin{forest}for tree={inner sep=0pt,outer sep=0pt, s sep=(2-level)*2mm, l=(8-level*level*level)*0.1mm}
  [,s sep=30
    [1
      [1][0][1]
    ]
  ]  
\end{forest}}

\subcaptionbox[Tree]{
    Tree
    \label{subfig:sublabel1}%
}
[0.3\textwidth]{
\begin{forest}for tree={inner sep=0pt,outer sep=0pt, s sep=(2-level)*2mm, l=(8-level*level*level)*0.1mm}
  [,s sep=30
    [1
      [1][0][1][0]
    ]
    [1
      [0][1]
    ]
  ]
\end{forest}
}
\hspace{0.1\textwidth}
\subcaptionbox[Tree]{
    Tree
    \label{subfig:sublabel1}%
}
[0.3\textwidth]{
\begin{forest}for tree={inner sep=0pt,outer sep=0pt, s sep=(2-level)*2mm, l=(8-level*level*level)*0.1mm}
  [,s sep=30
    [1
      [1][0][1][0]
    ]
    [1
      [0][1][0][0]
    ]
    [0]
    [1
      [1][0][0][0]
    ]
  ]
\end{forest}
}
\end{figure}
\end{document}

Edit: I found similar questions regarding Beamer and tried to craft a solution based on the code given by Qrrbrbirlbel, so far to no avail:

I tried:

\tikzset{
    invisible/.style={opacity=0,text opacity=0},
}
\forestset{
  invisible/.style={
    for tree={
      /tikz/invisible,
      edge={/tikz/invisible}}}}

and specified ,for children={invisible} after a node, unfortunately nothing happens.

  • 2
    Try using the built in style phantom instead of invisible. – Emma Oct 20 '16 at 13:34
  • 1
    Please note that you should attribute code which you get from somebody else's post, including a link for reference. – cfr Oct 20 '16 at 14:51
  • of course, I edited the question to include a link to the question – Jan B Oct 20 '16 at 14:59
6

Node option phantom takes the node into account when positioning, but does not draw it or the edges to/from it.

The following code achieves the desired effect for tree (c).

\begin{forest}for tree={inner sep=0pt,outer sep=0pt, s sep=(2-level)*2mm, l=(8-level*level*level)*0.1mm}
  [,s sep=30
    [1
      [1][0][1][0]
    ]
    [1,for nodewalk={3n}{phantom}
      [0][1][0][0]
    ]
    [0,phantom]
    [1,for tree=phantom
      [1][0][0][0]
    ]
  ]
\end{forest}

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.