1

I am trying to use a tree built by the forest package in a beamer animation. To uncover part of the tree (I want it to be revealed from bottom to top) I use the method described in Using beamer overlays with forest generated trees while modifying it slightly such that it only hides the current node and not the whole subtree.

The problem now is that I can manually hide the nodes by simply adding the visible on=<#> option, but for some reason this does not work when adding the option through a where statement.

The second part of the question was an oddity I discovered while trying to clean up my code - when combining the two forestset options, it no longer hides the edges as well as the nodes, but only the nodes. (Now even when adding the visibility statement manually.

The code I am trying this with is the following: (in the tree I added one position

\documentclass[]{beamer}

\usepackage[linguistics,external]{forest}

\usepackage{tikz}
\tikzset{highlight/.style={darkred,very thick},}
\tikzset{positive/.style={fill=examplegreen}}
\tikzset{negative/.style={fill=examplered}}
\colorlet{parameterblue}{rgb:cyan,2;white,4;blue,3}
\colorlet{examplegreen}{rgb:green,4;white,4;black,1}
\colorlet{examplered}{rgb:orange,2;red,3;white,4}
\colorlet{darkred}{red!80!black}
\colorlet{darkgreen}{green!80!black}
\newcommand{\plus}{\color{darkgreen}{$+$}}
\newcommand{\minus}{\color{darkred}{$-$}}
\tikzset{
  invisible/.style={opacity=0,text opacity=0},
  visible on/.style={alt={#1{}{invisible}}},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
  },
  beschr/.style={remember picture,overlay,font=\small},
  highlight on/.style={{alt=#1{highlight}{}}},
}
\forestset{
  highlight on/.style={/tikz/highlight on={#1},}
  }
\forestset{
  visible on/.style={
    % for tree={
    /tikz/visible on={#1},
    for children={
      edge={/tikz/visible on={#1}}}
    }
}


\begin{document}

\begin{frame}

   \begin{forest}
   %aligns the bottom lines
    where n children=0{tier=terminal,!u.tier=second,!uu.tier=third}{math content},
    where n children=0{!u.visible on=<2->,!uu.visible on=<3->,!uuu.visible on=<4->}{},
    for tree={l sep+=1em,}
   [ {\{m_7,m_{11}\}}
     [{\{m_8,m_9\}}
       [{\{m_1,m_2,m_4\}}
         [{\{m_1,m_3\}}
            [1][2],
         ]
         [{\{\dots\}}
           [3][4\\\plus]
         ]
       ]
       [{\{m_7\}}
         [ {\{m_7\}}
           [{5\onslide<5->{\\\minus}},for ancestors={edge={highlight on=<5->}},edge={highlight on=<5->}][6]
         ]
         [ {\{\dots\}}
           [7\\\plus][8\\\plus]
         ]
       ]
     ]
    [{\{\dots\}},visible on=<2->
     [{\{\dots\}}[9\\\minus][10]]
     [{\{\dots\}}[11][12\\\minus]]
    ]
   ]
   \end{forest}
\end{frame}
\end{document}

for the second part of the question, I exchanged the block containing the two forestset statements

\forestset{
  highlight on/.style={/tikz/highlight on={#1},}
  }
\forestset{
  visible on/.style={
    % for tree={
    /tikz/visible on={#1},
    for children={
      edge={/tikz/visible on={#1}}}
    }
}

by a single forestset statement

\forestset{
  highlight on/.style={/tikz/highlight on={#1},}
  visible on/.style={
    % for tree={
    /tikz/visible on={#1},
    for children={
      edge={/tikz/visible on={#1}}}
    }
}

and then it did not hide any of the edges. Any suggestions about what I am missing here?

  • You're missing a comma at the end of the highlight on line in the combo settings. highlight on/.style={/tikz/highlight on={#1},} -> highlight on/.style={/tikz/highlight on={#1},},. – cfr Sep 21 '17 at 22:15
3

Something like this, possibly. This is a modified version of some customisations I use, so credits for code are included as comments.

show me up

\documentclass[]{beamer}

\usepackage[linguistics]{forest}

\usepackage{tikz}
\tikzset{
  highlight/.style={darkred,very thick},
  positive/.style={fill=examplegreen},
  negative/.style={fill=examplered},
}
\colorlet{parameterblue}{rgb:cyan,2;white,4;blue,3}
\colorlet{examplegreen}{rgb:green,4;white,4;black,1}
\colorlet{examplered}{rgb:orange,2;red,3;white,4}
\colorlet{darkred}{red!80!black}
\colorlet{darkgreen}{green!80!black}
\newcommand{\plus}{\color{darkgreen}{$+$}}
\newcommand{\minus}{\color{darkred}{$-$}}
\tikzset{
  invisible/.style={opacity=0,text opacity=0},
  visible on/.style={alt={#1{}{invisible}}},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
  },
  highlight on/.style={{alt=#1{highlight}{}}},
}
\forestset{
  visible on/.style={% developed by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
    for tree={%
      /tikz/visible on={#1},
      edge={/tikz/visible on={#1}}}},
  highlight on/.style={%
    /tikz/highlight on={#1},
    edge={/tikz/highlight on={#1}}},
  highlight edge on/.style={%
    edge={/tikz/highlight on={#1}}},
  declare toks={no node before}{1},
  declare toks={no edge before}{1},
  declare count={gweladwy}{1},
  declare count={sleidiau}{1},
  not before/.style={%
    no node before=#1,
    for children={%
      no edge before=#1}},
  bottom up/.style={% based on Qrrbrbirlbel's answer at http://tex.stackexchange.com/a/112895/
    /tikz/visible on=<\forestoption{no node before}->,
    /tikz/every label/.append style={visible on=<\forestoption{no node before}->},
    /tikz/every edge label/.append style={visible on=<\forestoption{no edge before}->},
    edge={/tikz/visible on=<\forestoption{no edge before}->}},
  show me up/.style={
    before typesetting nodes={
      tempcounta/.max={>O{level}}{tree},
      where n children=0{
        tier=terminus, 
        no edge before=2,
      }{
        tempcountb/.process={ORw2+n{level}{tempcounta}{(##2-##1)+1}}, 
        tempcountc/.process={Rw+n{tempcountb}{##1+1}}, 
        tier/.register=tempcountb, 
        math content, 
        no node before/.register=tempcountb, 
        no edge before/.register=tempcountc,
      },
    },
    for tree={bottom up},
  },
}

\begin{document}
\begin{frame}
  \begin{forest}
    for tree={l sep+=1em},
    show me up
   [ {\{m_7,m_{11}\}}
     [{\{m_8,m_9\}}
       [{\{m_1,m_2,m_4\}}
         [{\{m_1,m_3\}}
            [1][2],
         ]
         [{\{\dots\}}
           [3][4\\\plus]
         ]
       ]
       [{\{m_7\}}
         [ {\{m_7\}}
           [{5\onslide<5->{\\\minus}}, for current and ancestors={highlight edge on=<5->}][6]
         ]
         [ {\{\dots\}}
           [7\\\plus][8\\\plus]
         ]
       ]
     ]
    [{\{\dots\}}%,visible on=<2->
     [{\{\dots\}}[9\\\minus][10]]
     [{\{\dots\}}[11][12\\\minus]]
    ]
   ]
   \end{forest}
\end{frame}
\end{document}

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.