在树中搜索动画(LaTeX Beamer,包森林)

在树中搜索动画(LaTeX Beamer,包森林)

是否可以在多张幻灯片上为树制作动画而不用为每张幻灯片编写明确的代码?

这就是我想要实现的目标,但代码较少(基本上我在搜索字符串“Ronny”)

\documentclass{beamer}
\usepackage{forest}
\begin{document}
    \frame{
        \begin{forest}
            for tree={
                circle,
                black,
                draw,
                minimum size = 2em,
                font=\Large,
                edge={->},
                s sep = 30pt
            }
            [{}, color=green
            [{}, edge label={node[midway, left]{J}}
            [{}, edge label={node[midway, left]{a}}
            [{}, double, edge label={node[midway, left]{ck}}]
            [{}, double, edge label={node[midway, right]{va}}]]
            [{}, double, edge label={node[midway, left]{im}}
            [{}, double, edge label={node[midway, left]{my}}]]]
            [{}, double, edge label={node[midway, right]{Ron}}
            [{}, double, edge label={node[midway, right]{ny}}]]]
     \end{forest}
 }
 \frame{
    \begin{forest}
        for tree={
            circle,
            black,
            draw,
            minimum size = 2em,
            font=\Large,
            edge={->},
            s sep = 30pt
        }
        [{}
        [{}, edge label={node[midway, left]{J}}
        [{}, edge label={node[midway, left]{a}}
        [{}, double, edge label={node[midway, left]{ck}}]
        [{}, double, edge label={node[midway, right]{va}}]]
        [{}, double, edge label={node[midway, left]{im}}
        [{}, double, edge label={node[midway, left]{my}}]]]
        [{}, color=green, double, edge label={node[midway, right]{Ron}}
        [{}, double, edge label={node[midway, right]{ny}}]]]
    \end{forest}
}
\frame{
    \begin{forest}
        for tree={
            circle,
            black,
            draw,
            minimum size = 2em,
            font=\Large,
            edge={->},
            s sep = 30pt
        }
        [{}
        [{}, edge label={node[midway, left]{J}}
        [{}, edge label={node[midway, left]{a}}
        [{}, double, edge label={node[midway, left]{ck}}]
        [{}, double, edge label={node[midway, right]{va}}]]
        [{}, double, edge label={node[midway, left]{im}}
        [{}, double, edge label={node[midway, left]{my}}]]]
        [{}, double, edge label={node[midway, right]{Ron}}
        [{}, color=green, double, edge label={node[midway, right]{ny}}]]]
    \end{forest}
}
\end{document}

答案1

基于如何使用 Tikz 节点制作投影仪覆盖

\documentclass{beamer}
\usepackage{forest}


\tikzset{onslide/.code args={<#1>#2}{%
  \only<#1>{\pgfkeysalso{#2}} % \pgfkeysalso doesn't change the path
}}


\begin{document}
    \begin{frame}
       \begin{forest}
            for tree={
                circle,
                black,
                draw,
                minimum size = 2em,
                font=\Large,
                edge={->},
                s sep = 30pt
            }
            [{}, onslide=<1>{color=green}
            [{}, edge label={node[midway, left]{J}}
            [{}, edge label={node[midway, left]{a}}
            [{}, double, edge label={node[midway, left]{ck}}]
            [{}, double, edge label={node[midway, right]{va}}]]
            [{}, double, edge label={node[midway, left]{im}}
            [{}, double, edge label={node[midway, left]{my}}]]]
            [{}, onslide=<2>{color=green}, double, edge label={node[midway, right]{Ron}}
            [{}, onslide=<3>{color=green}, double, edge label={node[midway, right]{ny}}]]]
     \end{forest}
\end{frame}

\end{document}

相关内容