6

My question refers to this question (I would comment there had I 50 reputation or more...).

I have a mindmap with arrows as in this question (motivated by this question) in a beamer document. I would like to reveal different children and arrows as I go.

Here's my tentative code (taken from several sources, amongst which Daniel's answer in here):

\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}

The first problem I encounter is that when children in level 2 are revealed, the links to children in level 3 are also revealed (before the children). How can I solve that?

Secondly, I do not know how to modify the code so the arrows don't appear all the time.

Could you help me? Thanks!

Ana
  • 137

1 Answers1

7

As explained in Daniel's answer you need to pass the visible on keys to the children, not to the nodes. Please note also that the visible on style is meanwhile part of the overlay-beamer-styles library. When I wrote \DrawArrowConnection, I already had in mind to improve it. Meanwhile Marijn added a very nice feature that allows one to draw double-headed arrows. This is a great trick. However, now there exist three versions of \DrawArrowConnection on the market, the original one, Marijn's nice upgrade, and the version from the older answer which you can find below. That's not optimal IMHO so I made it more TikZy and flexible. The upshot is that now everything is in a style and (optional) keys. All you need to do is to say something like

\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];

where the syntax of arrow connection is (hopefully) self-explaining:

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

arrow connection shift is Marijn's shift parameter, and arrow connection bend is a bending parameter whose initial value is 15 (with not other reason than that this looked reasonable in the settings of the original answer) but may be adjusted if the node distance varies. The reason for all this is to make it easier to upgrade it further without losing downward compatibility. And here is an 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}

enter image description here

Older (less elegant but working) answer: As for the \DrawArrowConnection, I have the habit of writing the commands in such a way that they allow for an optional parameter, which seems to pay off here. To draw the arrow connection only from slide 7 on you need only to do

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

Full code:

\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}

enter image description here

The white circles are artifacts of the conversion to an animated gif and are not present in the pdf output.

  • @ marmot: thanks a lot for you answer. I am sorry to have overlooked the info in Daniel's answer! However, the arrow thing is not working in my code. I had actually already tried that... Thanks! – Ana May 04 '19 at 07:33
  • @marmot: in fact, it does work, I hadn't understood I needed to modify the arrow code! Many thanks! – Ana May 04 '19 at 09:13
  • 1
    @Ana I added an IMHO better version that incorporates Marjin's nice upgrades and is easier to use and customize. –  May 04 '19 at 17:03