用箭头制作动画思维导图

用箭头制作动画思维导图

我的问题是指这个问题(如果我的声誉达到 50 点或者更高,我会在那里发表评论...)。

我有一张带有箭头的思维导图,如下所示这个问题(动机这个问题) 在 beamer 文档中。我想在前进的过程中展示不同的子项和箭头。

这是我的暂定代码(取自多个来源,其中包括 Daniel 的回答在这里):

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{mindmap,trees,shadows}
\usetikzlibrary{shapes.arrows,calc,positioning}%%For arrows
\newcommand{\DrawArrowConnection}[5][]{
\path let \p1=($(#2)-(#3)$),\n1={0.25*veclen(\x1,\y1)} in 
($(#2)!\n1!90:(#3)$) coordinate (#2-A)
($(#2)!\n1!270:(#3)$) coordinate (#2-B)
($(#3)!\n1!90:(#2)$) coordinate (#3-A)
($(#3)!\n1!270:(#2)$) coordinate (#3-B);
\foreach \Y in {A,B}
{
\pgfcoordinate{P-#2-\Y}{\pgfpointshapeborder{#2}{\pgfpointanchor{#3-\Y}{center}}}
\pgfcoordinate{P-#3-\Y}{\pgfpointshapeborder{#3}{\pgfpointanchor{#2-\Y}{center}}}
}
\shade let \p1=($(#2)-(#3)$),\n1={atan2(\y1,\x1)-90} in
[top color=#4,bottom color=#5,shading angle=\n1] (P-#2-A) 
 to[bend left=15] ($($(P-#2-A)!0.4!(P-#3-B)$)!0.25!($(P-#2-B)!0.4!(P-#3-A)$)$)
-- ($($(P-#2-A)!0.4!(P-#3-B)$)!3.14pt!270:(P-#3-B)$)
-- ($($(P-#2-A)!0.6!(P-#3-B)$)!0.25!($(P-#2-B)!0.4!(P-#3-A)$)$) 
to[bend left=15] (P-#3-B) --
 (P-#3-A)  to[bend left=15] 
($($(P-#3-A)!0.4!(P-#2-B)$)!0.25!($(P-#3-B)!0.6!(P-#2-A)$)$)
-- ($($(P-#3-A)!0.6!(P-#2-B)$)!3.14pt!270:(P-#2-B)$)
-- ($($(P-#3-A)!0.6!(P-#2-B)$)!0.25!($(P-#3-B)!0.6!(P-#2-A)$)$) 
to[bend left=15] (P-#2-B) -- cycle;
}

\begin{document}
 % Keys to support piece-wise uncovering of elements in TikZ pictures:
  % \node[visible on=<2->](foo){Foo}
  % \node[visible on=<{2,4}>](bar){Bar}   % put braces around comma expressions
  %
  % Internally works by setting opacity=0 when invisible, which has the 
  % adavantage (compared to \node<2->(foo){Foo} that the node is always there, hence
  % always consumes space plus that coordinate (foo) is always available.
  %
  % The actual command that implements the invisibility can be overriden
  % by altering the style invisible. For instance \tikzsset{invisible/.style={opacity=0.2}}
  % would dim the "invisible" parts. Alternatively, the color might be set to white, if the
  % output driver does not support transparencies (e.g., PS) 
  %
  \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{frame}
\begin{tikzpicture}
\path[mindmap, concept color=black, text=white,
  level 1 concept/.append style={level distance=27mm, sibling angle=90},
  level 2 concept/.append style={level distance=17mm, sibling angle=90},every node/.append style={scale=0.6}]
node[concept] {A}
[clockwise from=135]
child[concept color=blue,visible on=<8->] {
  node(B)[concept] {B}
  [clockwise from=135, level 2 concept/.append style={sibling angle=50}]
  child {node[concept] {b1}}
  }
child[concept color=green!60!black, visible on=<5->] {
  node(C)[concept] {C}
  [clockwise from=90]
  child{node(c1)[concept,visible on=<6->] {c1}}
  child{node(c2)[concept,visible on=<7->] {c2}}}
child[concept color=red!60!black, visible on=<2->] {
  node[concept] {D}
  [clockwise from=0]
 child{node[concept, visible on=<3->] {d1}}
  child{node[concept, visible on=<4->] {d2}}
  }
child[concept color=yellow!60!black,visible on=<8->] {
  node[concept] {E}
  }
  ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%           CONNECTIONS
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DrawArrowConnection{c1}{c2}{green!60!black}{green!60!black}
\end{tikzpicture}
\end{frame}
\end{document}

我遇到的第一个问题是,当显示第 2 级的子级时,第 3 级的子级链接也会显示(在子级之前)。我该如何解决这个问题?

其次,我不知道如何修改代码以使箭头不会一直出现。

你能帮助我吗?谢谢!

答案1

正如解释的那样丹尼尔的回答您需要将visible on键传递给children,而不是节点。请注意,样式visible on同时也是库的一部分overlay-beamer-styles。当我写的时候\DrawArrowConnection,我已经想要改进它。 同时Marijn 添加了一项非常好的功能,可以绘制双头箭头\DrawArrowConnection。这是一个很棒的技巧。然而,现在市场上有三个版本,原始的Marijn 的出色升级以及您可以在下面找到的旧答案的版本。在我看来,这不是最佳选择,所以我让它更 Ti简单又灵活。结果是现在一切都在样式和(可选)键中。您需要做的就是说类似

\path[visible on=<7->,arrow connection shift=0.1,arrow connection bend=12,
arrow connection=from c1 to c2 varying color green!60!black to green!60!black];

箭头连接的语法(希望)是不言自明的:

arrow connection=from <start> to <target> varying color <start color> to <end color> ,

arrow connection shiftMarijn 的移位参数,并且arrow connection bend是弯曲参数,其初始值为 15(没有其他原因,只是因为这在原始答案的设置中看起来合理),但如果节点距离发生变化,可能会进行调整。 这样做的原因是为了更容易进一步升级而不会失去向下兼容性。 这是一个 MWE

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{mindmap,overlay-beamer-styles}
\usetikzlibrary{shapes.arrows,calc,positioning}%%For arrows
\tikzset{arrow connection shift/.initial=0,arrow connection bend/.initial=15,
arrow connection/.style args={from #1 to #2 varying color #3 to #4}{%
insert path={
 let \p1=($(#1)-(#2)$),\n1={0.25*veclen(\x1,\y1)} in 
($(#1)!\n1!90:(#2)$) coordinate (#1-A)
($(#1)!\n1!270:(#2)$) coordinate (#1-B)
($(#2)!\n1!90:(#1)$) coordinate (#2-A)
($(#2)!\n1!270:(#1)$) coordinate (#2-B)
\pgfextra{
\foreach \Y in {A,B}
{
\pgfcoordinate{P-#1-\Y}{\pgfpointshapeborder{#1}{\pgfpointanchor{#2-\Y}{center}}}
\pgfcoordinate{P-#2-\Y}{\pgfpointshapeborder{#2}{\pgfpointanchor{#1-\Y}{center}}}
}
}
let \p1=($(#1)-(#2)$),\n1={atan2(\y1,\x1)-90} in
[top color=#3,bottom color=#4,shading angle=\n1] (P-#1-A) 
 to[bend left=15] ($($(P-#1-A)!{0.4+\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#2-B)$)!0.25!($(P-#1-B)!{0.4+\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#2-A)$)$)
-- ($($(P-#1-A)!{0.4+\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#2-B)$)!3.14pt!270:(P-#2-B)$)
-- ($($(P-#1-A)!{0.6+\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#2-B)$)!0.25!($(P-#1-B)!{0.4+\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#2-A)$)$) 
to[bend left=\pgfkeysvalueof{/tikz/arrow connection bend}] (P-#2-B) --
 (P-#2-A)  to[bend left=\pgfkeysvalueof{/tikz/arrow connection bend}] 
($($(P-#2-A)!{0.4-\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#1-B)$)!0.25!($(P-#2-B)!{0.6-\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#1-A)$)$)
-- ($($(P-#2-A)!{0.6-\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#1-B)$)!3.14pt!270:(P-#1-B)$)
-- ($($(P-#2-A)!{0.6-\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#1-B)$)!0.25!($(P-#2-B)!{0.6-\pgfkeysvalueof{/tikz/arrow connection shift}}!(P-#1-A)$)$) 
to[bend left=15] (P-#1-B) -- cycle
}}}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\path[mindmap, concept color=black, text=white,
  level 1 concept/.append style={level distance=27mm, sibling angle=90},
  level 2 concept/.append style={level distance=17mm, sibling angle=90},every node/.append style={scale=0.6}]
node[concept] {A}
[clockwise from=135]
child[concept color=blue,visible on=<8->] {
  node(B)[concept] {B}
  [clockwise from=135, level 2 concept/.append style={sibling angle=50}]
  child {node[concept] {b1}}
  }
child[concept color=green!60!black, visible on=<5->] {
  node(C)[concept] {C}
  [clockwise from=90]
  child[visible on=<6->]{node(c1)[concept] {c1}}
  child[visible on=<7->]{node(c2)[concept] {c2}}}
child[concept color=red!60!black, visible on=<2->] {
  node[concept] {D}
  [clockwise from=0]
 child[visible on=<3->]{node[concept] {d1}}
  child[visible on=<4->]{node[concept] {d2}}
  }
child[concept color=yellow!60!black,visible on=<8->] {
  node[concept] {E}
  }
  ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%           CONNECTIONS
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\path[visible on=<7->,arrow connection shift=0.1,arrow connection bend=12,
arrow connection=from c1 to c2 varying color green!60!black to green!60!black];
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

较旧的(不太优雅但有效)答案:至于\DrawArrowConnection,我习惯以允许使用可选参数的方式编写命令,这似乎在这里很有用。要从幻灯片 7 开始仅绘制箭头连接,您只需执行

\DrawArrowConnection[visible on=<7->]{c1}{c2}{green!60!black}{green!60!black}

完整代码:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{mindmap,overlay-beamer-styles}
\usetikzlibrary{shapes.arrows,calc,positioning}%%For arrows
\newcommand{\DrawArrowConnection}[5][]{
\path let \p1=($(#2)-(#3)$),\n1={0.25*veclen(\x1,\y1)} in 
($(#2)!\n1!90:(#3)$) coordinate (#2-A)
($(#2)!\n1!270:(#3)$) coordinate (#2-B)
($(#3)!\n1!90:(#2)$) coordinate (#3-A)
($(#3)!\n1!270:(#2)$) coordinate (#3-B);
\foreach \Y in {A,B}
{
\pgfcoordinate{P-#2-\Y}{\pgfpointshapeborder{#2}{\pgfpointanchor{#3-\Y}{center}}}
\pgfcoordinate{P-#3-\Y}{\pgfpointshapeborder{#3}{\pgfpointanchor{#2-\Y}{center}}}
}
\shade[#1] let \p1=($(#2)-(#3)$),\n1={atan2(\y1,\x1)-90} in
[top color=#4,bottom color=#5,shading angle=\n1] (P-#2-A) 
 to[bend left=15] ($($(P-#2-A)!0.4!(P-#3-B)$)!0.25!($(P-#2-B)!0.4!(P-#3-A)$)$)
-- ($($(P-#2-A)!0.4!(P-#3-B)$)!3.14pt!270:(P-#3-B)$)
-- ($($(P-#2-A)!0.6!(P-#3-B)$)!0.25!($(P-#2-B)!0.4!(P-#3-A)$)$) 
to[bend left=15] (P-#3-B) --
 (P-#3-A)  to[bend left=15] 
($($(P-#3-A)!0.4!(P-#2-B)$)!0.25!($(P-#3-B)!0.6!(P-#2-A)$)$)
-- ($($(P-#3-A)!0.6!(P-#2-B)$)!3.14pt!270:(P-#2-B)$)
-- ($($(P-#3-A)!0.6!(P-#2-B)$)!0.25!($(P-#3-B)!0.6!(P-#2-A)$)$) 
to[bend left=15] (P-#2-B) -- cycle;
}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\path[mindmap, concept color=black, text=white,
  level 1 concept/.append style={level distance=27mm, sibling angle=90},
  level 2 concept/.append style={level distance=17mm, sibling angle=90},every node/.append style={scale=0.6}]
node[concept] {A}
[clockwise from=135]
child[concept color=blue,visible on=<8->] {
  node(B)[concept] {B}
  [clockwise from=135, level 2 concept/.append style={sibling angle=50}]
  child {node[concept] {b1}}
  }
child[concept color=green!60!black, visible on=<5->] {
  node(C)[concept] {C}
  [clockwise from=90]
  child[visible on=<6->]{node(c1)[concept] {c1}}
  child[visible on=<7->]{node(c2)[concept] {c2}}}
child[concept color=red!60!black, visible on=<2->] {
  node[concept] {D}
  [clockwise from=0]
 child[visible on=<3->]{node[concept] {d1}}
  child[visible on=<4->]{node[concept] {d2}}
  }
child[concept color=yellow!60!black,visible on=<8->] {
  node[concept] {E}
  }
  ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%           CONNECTIONS
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DrawArrowConnection[visible on=<7->]{c1}{c2}{green!60!black}{green!60!black}
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

白色圆圈是转换为动画 gif 的产物,在 pdf 输出中不存在。

相关内容