发现树节点

发现树节点

考虑以下代码:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees}

\tikzset{
  invisible/.style={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
  },
}    

\begin{document}
\begin{frame}
      \begin{tikzpicture}[overlay,remember picture,
      level 1/.style={level distance=12mm,every child/.style={edge from parent/.style={->,solid,draw=blue}} },
      level 2/.style={sibling distance=12mm,every child/.style={edge from parent/.style={->,solid,draw=blue}}},
      level 3/.style={sibling distance=8mm,every child/.style={edge from parent/.style={->,solid,draw=blue}}},
      semithick]

      \node[draw=none,text=red] {S}
      child[visible on=<2,3>] {node[draw=none,text=red] (a)  {A}};

    \end{tikzpicture}
\end{frame}
\end{document}

,如果我在选项中使用逗号指定幻灯片范围,则会收到错误visible on。如果我使用指定范围,效果会很好2-3

答案1

问题是逗号被解释为不同选项之间的分隔符。当您设置的键值包含时,,您应该使用和来保护它{}在您的情况下,您应该使用visible on={<2,3>}

在这种情况下,查看值的使用方式,您还应该在包含定义的行中添加括号visible on,如下所示:visible on/.style={alt={#1{}{invisible}}},

因此,您的示例的工作版本是:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees}

\tikzset{
  invisible/.style={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
  },
}

\begin{document}
\begin{frame}
      \begin{tikzpicture}[overlay,remember picture,
      level 1/.style={level distance=12mm,every child/.style={edge from parent/.style={->,solid,draw=blue}} },
      level 2/.style={sibling distance=12mm,every child/.style={edge from parent/.style={->,solid,draw=blue}}},
      level 3/.style={sibling distance=8mm,every child/.style={edge from parent/.style={->,solid,draw=blue}}},
      semithick]

      \node[draw=none,text=red] {S}
      child[visible on={<2,3>}] {node[draw=none,text=red] (a)  {A}};

    \end{tikzpicture}
\end{frame}
\end{document}

相关内容