第二次尝试

第二次尝试

以下是对这一“挑战”的回答:

\documentstyle[beamer]
\usepackage{tikz}

\begin{document}
\begin{frame}
\tikzset{click/.style={draw}}

\begin{tikzpicture}[start chain=going right,
    node distance=4mm,
every node/.style={on chain,draw}]

\node(A)  {Alpha};
\node(B)  {Bravo};
\node(C)  {Charlie};
\node(D) {Delta};
\node(E)  {Echo};
\node(F) {Foxtrot};
\end{tikzpicture}


\play{F,E,E,D}
\play{D,E,A,F}
\play{B,E,D}

\end{frame}
\end{document}

问题是如何定义“点击”,以便在每个覆盖中,突出显示的节点都会发生变化。

在伪代码中,“click”应该定义为:

If currentStep = myNodeName then
   add "ultra thick", or "fill=green", or whatever
   to the current node.
fi

理想情况下,[click] 宏应该适用于任何路径,而不仅仅是节点。

同时,“\play”应该翻译为

Foreach currentStep in argumentList do
  \only<+> {
      invoke the above tikzpicture while setting currentStep
   }
od

*更多信息 *

这是几乎可以正常工作的东西

tikzset{
  Z/.code={
    \ifthenelse{\equal{\noexpand\pc}{#1}}{%
  \tikzset{rectangle}%
    }{%
  \tikzset{circle}%
    }
  }
}
\begin{frame}[fragile,label=current]{my frame}
  \foreach \pc in {A,B,A,D,C,A} { 
  \only<+>{
    \begin{tikzpicture}[start chain=going right,node distance=1cm]
      \node[on chain][draw,Z=A] {A\pc};
      \node[on chain][draw,Z=B] {B\pc};
      \node[on chain][draw,Z=C] {C\pc};
      \node[on chain][draw,Z=D] {D\pc};
    \end{tikzpicture}
  }
}
\end{frame}

但是,扩展过程中肯定有我遗漏的地方。逻辑似乎正确,文档编译得很好,但条件的真正分支从未执行过。有什么想法吗?

答案1

第二次尝试

(警告:需要 TikZ 3.0!)

额外填写的要求(所有其他填写的要求请参阅下面的第一次尝试):

  • 允许通过special prev样式进行“衰减”。每个命名关键字(例如kw)必须提供三种样式:kwspecial kwspecial prev kw

  • 可以通过 键选择“程序计数器”的名称(\pc)及其先前的值( ) 。\pcprevZ choose macros

在此处输入图片描述

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains,shadows}
\tikzset{
  Z apply special/.style={special #1},
  Z apply special prev/.style={special prev #1},
  Z choose macros/.style 2 args={
    Z/.style={normal,
      Z apply special prev/.list/.expand once=#2,%
      Z apply special/.list/.expand once=#1,%
      ##1},
  },
}
\begin{document}
\begin{frame}
  \begin{tikzpicture}
    \tikzset{
      % choose macros name
      Z choose macros={\pc}{\pcprev},
      % global style for all nodes
      my node/.style={
        align=center,font=\footnotesize,anchor=center,line width=1pt,
        inner sep=1em,circle,line width=2pt,
      },
      my double/.style={double=white,double distance=1mm,draw=black},
      % normal styles for each keyword
      normal/.style={
        A1/.style={my node,black,fill=white,draw},
        B2/.style={my node,black,fill=white,draw},
        key word/.style={my node,black,fill=white,draw},
        a path/.style={draw=black,line width=1mm},
      },
      % styles for previous states for each keyword
      special prev A1/.style={A1/.append style={fill=red!50!white}},
      special prev B2/.style={B2/.append style={fill=lime!50!white}},
      special prev key word/.style={key word/.append style={fill=cyan!50!white}},
      special prev a path/.style={a path/.append style={draw=orange!50!white}},
      % styles for special state for each keyword
      special A1/.style={A1/.append style={my double,fill=red,drop shadow}},
      special B2/.style={B2/.append style={my double,fill=lime,drop shadow}},
      special key word/.style={key word/.append style={my double,fill=cyan}},
      special a path/.style={a path/.append style={my double,draw=orange}},
    }
    \foreach \pc [remember=\pc as \pcprev (initially \pc)] in {
      A1, B2, A1, a path, key word,
      {A1,B2}, {key word, a path}
    } {
      \only<+>{
        \node[anchor=base west,align=left] at (0,2) {current: \pc\\
          (prev: \pcprev)};
        \node[Z=A1] (A1) at (0,0) {A1};
        \node[Z=B2] (B2) at (3,0) {B2};
        \node[Z=key word] (key word) at (6,0) {key word};
        \draw[Z=a path]
        (A1) -- (B2)
        (B2) -- (key word)
        (key word) to[out=-145,in=-35] (A1);
      }
    }
    \path (-2,-2) (5,3); % fixed bounding box
  \end{tikzpicture}
\end{frame}
\end{document}

第一次尝试

这是一次无需任何测试的尝试!

已填写要求:

  • 不仅支持节点,还支持任意路径元素。
  • 允许更长的符号名称。
  • 允许\pc包含多个节点[...]

已填写未制定的要求:

  • 支持每个关键字不同的普通样式和特殊样式。

在此处输入图片描述

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{frame}
  \begin{tikzpicture}[start chain=going right,on grid,node distance=2cm]
    \tikzset{
      every node/.style={align=center,font=\footnotesize,anchor=base},
      % normal styles for each keywords
      normal/.style={
        A1/.style={rectangle,black,fill=gray},
        B2/.style={rectangle,black,fill=red!20},
        key word/.style={rectangle,black},
        4th item/.style={black},
      },
      % special styles for each keywords
      special A1/.style={A1/.style={circle,red}},
      special B2/.style={B2/.style={circle,olive}},
      special key word/.style={key word/.style={circle,blue}},
      special 4th item/.style={4th item/.style={double=white,draw=orange,line width=1pt}},
      % select the special styles to apply
      apply special/.style={special ####1},
      Z/.style={normal,apply special/.list/.expand once=\pc,####1},
    }
    \foreach \pc in {A1, B2, A1, 4th item, key word, {A1,B2}, {key word, 4th item}} { 
      \only<+>{
        \node[overlay] at (4,1) {\pc};
        \node[on chain,draw,Z=A1] {A1};
        \node[on chain,draw,Z=B2] {B2};
        \node[on chain,draw,Z=key word] {key word};
        \draw[Z=4th item,rounded corners] (5,-1) rectangle (7,1);
      }
    }
    \path (-1,-2) (8,2); % fixed bounding box
  \end{tikzpicture}
\end{frame}
\end{document}

答案2

对于您的更新,以下内容有效(如果我理解正确的话)

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\tikzset{
  Z/.code={\expandafter\if\pc#1\relax\tikzset{shape=rectangle}\else\tikzset{shape=circle}\fi}
}

\begin{document}
\begin{frame}[fragile,label=current]{my frame}
  \foreach \pc in {A,B,A,D,C,A} { 
  \only<+>{
    \begin{tikzpicture}[start chain=going right,node distance=1cm]
      \node[on chain,draw,Z=A] {A\pc};
      \node[on chain,draw,Z=B] {B\pc};
      \node[on chain,draw,Z=C] {C\pc};
      \node[on chain,draw,Z=D] {D\pc};
    \end{tikzpicture}
  }
}
\end{frame}

\end{document}

相关内容