3

My question refers to this discussion (it would be easier to comment there, but I am not allowed due to my low reputation; I suggest this be changed...)

Here's my code, shamelessly copied from the aforementioned great answers

\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{mindmap}

\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}
\begin{tikzpicture}
\path[mindmap, concept color=black, text=white,
  level 1 concept/.append style={level distance=52mm, sibling angle=90},
  level 2 concept/.append style={sibling angle=90}]
node[concept] {A}
[clockwise from=135]
child[concept color=blue] {
  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] {
  node(C)[concept] {C}
  [clockwise from=90]
  child{node(c1)[concept] {c1}}
  child{node(c2)[concept] {c2}}}
child[concept color=red!60!black] {
  node[concept] {D}
  [clockwise from=0]
  child{node[concept] {d1}}
  child{node[concept] {d2}}
  }
child[concept color=yellow!60!black] {
  node[concept] {E}
  }
  ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%           CONNECTIONS
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DrawArrowConnection{B}{C}{blue}{green!60!black}
\DrawArrowConnection{c1}{c2}{green!60!black}{green!60!black}
\DrawArrowConnection{c2}{c1}{green!60!black}{green!60!black}
\end{tikzpicture}
\end{document}

I need a double headed arrow between c1 and c2, but I do not see how to displace the heads, so I tried two arrows (one back, one forth), which gives a not at all nice result...Any ideas?

Many thanks!

Ana
  • 137

1 Answers1

3

The arrows in the answer by marmot to the earlier question are drawn in the paths at the end of the DrawArrowConnection macro, with coordinates like ($($(P-#2-A)!0.4!(P-#3-B)$)!0.25!($(P-#2-B)!0.4!(P-#3-A)$)$). You can change the offsets of the coordinate (in the example 0.4) to shift the position of the arrows.

A bit of explanation: an arrow head is drawn as two triangles, one on each side of the line. This is done using the \shade command in the macro. A triangle consists of coordinates connected by --. The coordinates use (a complex version of) the syntax ($(A)!0.n!(B)$), which means between A and B at position 0.n. So if you want to change the position of the arrow head, you should change the value of 0.n here.

The arrow heads range from 0.4 to 0.6, calculated from the origin (one side of the arrow head) or the destination (other side). So to shift the arrow head closer to the origin by 0.1, you need to set the positions to 0.3 and 0.5 on one side, and 0.5 and 0.7 on the other side. The calculations are done with \pgfmathsetmacro (by adding or subtracting the value of argument #6 to/from 0.4 and 0.6, respectively), and the macros assigned with this command (\shiftstarta etc.) are inserted in the coordinates instead of the originally used 0.4 and 0.6 values.

Code:

\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{mindmap}
\usetikzlibrary{shapes.arrows,calc,positioning}%%For arrows
% modified: added argument #6 for arrow head shift
\newcommand{\DrawArrowConnection}[6][]{
\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}}}
}
\pgfmathsetmacro{\shiftstarta}{0.4+#6} % modified: added offset calculations
\pgfmathsetmacro{\shiftenda}{0.6+#6}   % 
\pgfmathsetmacro{\shiftstartb}{0.4-#6} %
\pgfmathsetmacro{\shiftendb}{0.6-#6}   % end of offset calculations
% modified below: occurrences of 0.4 and 0.6 replaced by the offset macros
\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)!\shiftstarta!(P-#3-B)$)!0.25!($(P-#2-B)!\shiftstarta!(P-#3-A)$)$)
-- ($($(P-#2-A)!\shiftstarta!(P-#3-B)$)!3.14pt!270:(P-#3-B)$)
-- ($($(P-#2-A)!\shiftenda!(P-#3-B)$)!0.25!($(P-#2-B)!\shiftstarta!(P-#3-A)$)$) 
to[bend left=15] (P-#3-B) --
 (P-#3-A)  to[bend left=15] 
($($(P-#3-A)!\shiftstartb!(P-#2-B)$)!0.25!($(P-#3-B)!\shiftendb!(P-#2-A)$)$)
-- ($($(P-#3-A)!\shiftendb!(P-#2-B)$)!3.14pt!270:(P-#2-B)$)
-- ($($(P-#3-A)!\shiftendb!(P-#2-B)$)!0.25!($(P-#3-B)!\shiftendb!(P-#2-A)$)$) 
to[bend left=15] (P-#2-B) -- cycle;
}
\begin{document}
\begin{tikzpicture}
\path[mindmap, concept color=black, text=white,
  level 1 concept/.append style={level distance=52mm, sibling angle=90},
  level 2 concept/.append style={sibling angle=90}]
node(A)[concept] {A}
[clockwise from=135]
child[concept color=blue] {
  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] {
  node(C)[concept] {C}
  [clockwise from=90]
  child{node(c1)[concept] {c1}}
  child{node(c2)[concept] {c2}}}
child[concept color=red!60!black] {
  node[concept] {D}
  [clockwise from=0]
  child{node[concept] {d1}}
  child{node[concept] {d2}}
  }
child[concept color=yellow!60!black] {
  node[concept] {E}
  }
  ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%           CONNECTIONS
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% modified: added shift parameter to all \DrawArrowConnection calls
% first arrow: value 0, no shift
\DrawArrowConnection{B}{C}{blue}{green!60!black}{0}
% arrows between c1 and c2: shift by -0.1 (closer to origin)
\DrawArrowConnection{c1}{c2}{green!60!black}{green!60!black}{-0.1}
\DrawArrowConnection{c2}{c1}{green!60!black}{green!60!black}{-0.1}
% arrows between A and C: shift by 0.15 (further from origin)
\DrawArrowConnection{A}{C}{black}{green!60!black}{0.15}
\DrawArrowConnection{C}{A}{green!60!black}{black}{0.15}
\end{tikzpicture}
\end{document}

Result:

enter image description here

Marijn
  • 37,699