答案1
第二次更新
现在我重新阅读了这个问题,这是一种tricolor
风格;首先测量路径的总长度,然后将三种颜色应用于路径的每个第三部分:
代码:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\newlength\mylen
\tikzset{
tricolor/.style n args={3}{
decoration={
markings,
mark=at position 0.5 with {
\node[draw=none,inner sep=0pt,fill=none,text width=0pt,minimum size=0pt] {\global\setlength\mylen{\pgfdecoratedpathlength}};
},
},
draw=#1,
dash pattern=on 0.333333\mylen off 0.666666\mylen,
preaction={decorate},
postaction={
draw=#2,
dash pattern=on 0.333333\mylen off 0.333333\mylen,dash phase=0.333333\mylen
},
postaction={
draw=#3,
dash pattern=on 0.333333\mylen off 0.666666\mylen,dash phase=0.333333\mylen
},
}
}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}[
line width=1pt,
every node/.append style={draw,circle,minimum size=3em},
>=latex
]
\node (a) at (-5,3) {a};
\node (b) at (-5,0) {b};
\node (bbb) at (0,0) {bbb};
\node (aaa) at (180:3) {aaa};
\node (baa) at (150:3) {baa};
\node (aba) at (120:3) {aba};
\node (aab) at (90:3) {aab};
\node (bba) at (60:3) {bba};
\node (bab) at (30:3) {bab};
\node (abb) at (0:3) {abb};
\draw[->,red!80!black]
(a) -- (b);
\draw[->,cyan]
(b) to[out=210,in=330,looseness=4] (b);
\draw[red!80!black,->]
(aaa) -- (bbb);
\draw[->,tricolor={cyan}{red!80!black}{red!80!black}]
(baa) to[out=-80,in=150] (bbb);
\draw[->,tricolor={red!80!black}{cyan}{red!80!black}]
(aba) to[out=-100,in=120] (bbb);
\draw[->,tricolor={red!80!black}{red!80!black}{cyan}]
(aab) -- (bbb);
\draw[->,tricolor={cyan}{cyan}{red!80!black}]
(bba) to[out=280,in=60] (bbb);
\draw[->,tricolor={cyan}{red!80!black}{cyan}]
(bab) to[out=260,in=30] (bbb);
\draw[->,tricolor={red!80!black}{cyan}{cyan}]
(abb) -- (bbb);
\draw[cyan]
(bbb) to[out=210,in=330,looseness=4] (bbb);
\end{tikzpicture}
\end{frame}
\end{document}
当然,三色可以在真正的三种不同颜色环境中使用:
代码:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\newlength\mylen
\tikzset{
tricolor/.style n args={3}{
decoration={
markings,
mark=at position 0.5 with {
\node[draw=none,inner sep=0pt,fill=none,text width=0pt,minimum size=0pt] {\global\setlength\mylen{\pgfdecoratedpathlength}};
},
},
draw=#1,
dash pattern=on 0.333333\mylen off 0.666666\mylen,
preaction={decorate},
postaction={
draw=#2,
dash pattern=on 0.333333\mylen off 0.333333\mylen,dash phase=0.333333\mylen
},
postaction={
draw=#3,
dash pattern=on 0.333333\mylen off 0.666666\mylen,dash phase=0.333333\mylen
},
}
}
\begin{document}
\begin{frame}
\begin{tikzpicture}[line width=1pt]
\node (a) at (0,0) {a};
\node (b) at (2,-3) {b};
\node (c) at (4,3) {c};
\draw[->,tricolor={red}{blue}{brown}]
(a) to[out=-60,in=90] (b);
\draw[->,tricolor={green}{magenta}{yellow}]
(c) to[out=-60,in=90] (a);
\draw[->,tricolor={olive}{cyan}{orange}]
(c.0) to[out=0,in=0] (b.0);
\end{tikzpicture}
\end{frame}
\end{document}
更新
最初的想法相同,但现在使用一种风格:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations}
\tikzset{
bicolor/.style 2 args={
dashed,dash pattern=on 20pt off 20pt,->,#1,
postaction={draw,dashed,dash pattern=on 20pt off 20pt,->,#2,dash phase=20pt}
},
}
\begin{document}
\begin{frame}
\begin{tikzpicture}[line width=1pt]
\node (a) at (0,0) {a};
\node (b) at (2,-3) {b};
\node (c) at (4,3) {c};
\draw[bicolor={red}{blue}]
(a) to[out=-60,in=90] (b);
\draw[bicolor={green}{magenta}]
(c) to[out=-60,in=90] (a);
\end{tikzpicture}
\end{frame}
\end{document}
一种简单的可能性是绘制两次路径,分别使用相同dash pattern
和不同的路径dash phase
:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{tikzpicture}[line width=1pt]
\node (a) at (0,0) {a};
\node (b) at (2,-3) {b};
\draw[dashed,dash pattern=on 20pt off 20pt,->,red]
(a) to[out=-60,in=90] (b);
\draw[dashed,dash pattern=on 20pt off 20pt,->,blue,dash phase=20pt]
(a) to[out=-60,in=90] (b);
\end{tikzpicture}
\end{frame}
\end{document}