我想使用 tikz 树绘制流程图。
我想改变一些边缘的样式。我希望从 W 到 GI2 和 GI4 的边缘是弯曲的。
我尝试使用child from parent path={...
,但它不起作用(有问题\tikzparentnode
?)。
你能解释一下怎么做吗?
谢谢!
这是我的代码
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows,shapes,shapes.arrows,trees}
\tikzset{
wait/.style={circle, draw=black, text centered, anchor=north, text=black, font=\scriptsize},
adopt/.style={single arrow, draw=black, minimum height=1cm, minimum width=0.8cm, single arrow head extend=.15cm, inner sep=0.1cm, text centered, anchor=north, text=black, font=\footnotesize},
end/.style={draw=none, fill=none, text centered, anchor=north}
}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}[level distance=0.3cm, growth parent anchor=south,sibling distance = 3.7cm, align=center]
\node (start) [end] {Begin $P_{I0-1}$} [->]
child{[level distance=0.5cm]
node (adopt5) [adopt, label=0:{\textbf{label 1}}] {$G_{I1}$}
child{[level distance=1cm, sibling distance=5cm]
node (w) [wait] {$\mathcal{W}$}
child{[level distance=0.6cm]
node (g1) [adopt, label=0:{\textbf{label 2}}] {$G_{I2}(f)$}
child{
node (bye1) [end] {}
}
edge from parent node[pos=0.2,left=0.6cm] {label on edge 1}
}
child{[level distance=0.6cm]
node (g2) [adopt, label=0:{\textbf{label 3}}] {$G_{I3}(f)$}
child{
node (bye2) [end] {}
}
edge from parent node[pos=0.3] {label on edge 2}
}
child{[level distance=0.6cm]
node (g3) [adopt, label=0:{\textbf{label 4}}] {$G_{I4}(f)$}
child{[-]
node (bye3) [end] {}
}
edge from parent node[pos=0.2,right=0.6cm] {label on edge 3}
}
}
};
\draw [->] (bye3.north) -- (bye2.north) -- (bye1.north) -- (-6cm,-4.63cm) -- (-6cm,-1.6cm) -- (0cm,-1.6cm);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
为什么要使用tree
?
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows,shapes,shapes.arrows,trees}
\tikzset{
wait/.style={circle, draw=black, text centered, anchor=north, text=black, font=\scriptsize},
adopt/.style={single arrow, draw=black, minimum height=1cm, minimum width=0.8cm, single arrow head extend=.15cm, inner sep=0.1cm, text centered, anchor=north, text=black, font=\footnotesize},
end/.style={draw=none, fill=none, text centered, anchor=north}
}
\begin{document}
\begin{tikzpicture}[]
\node[end] (start) [end] {Begin $P_{I0-1}$};
\node[adopt] (adopt5) [below=0.5 of start, label=0:{\textbf{label 1}}] {$G_{I1}$};
\node[wait] (w) [below=1cm of adopt5] {$\mathcal{W}$};
\node[adopt, below left=1cm and 3.7cm of w] (g1) [label=0:{\textbf{label 2}}] {$G_{I2}(f)$};
\node[adopt, below right=1cm and 3.7cm of w] (g3) [label=0:{\textbf{label 4}}] {$G_{I4}(f)$};
\node[adopt,anchor=center] (g2) [label=0:{\textbf{label 3}}] at (g1-|w) {$G_{I3}(f)$};
\draw[->] (start)--(adopt5);
\draw[->] (adopt5)-- coordinate (aux) (w);
\draw[->] (w) to [out=185, in=90] node[above left]{label on edge 1} (g1.north);
\draw[->] (w) -- node{label on edge 2} (g2.north);
\draw[->] (w) to [out=-5, in=90] node[above right]{label on edge 3} (g3.north);
\draw[->] (g1.south)--++(-90:1cm);
\draw[->] (g2.south)--++(-90:1cm);
\draw[->] (g3.south)|-([shift={(-1cm,-1cm)}]g1.south west)|-(aux);
\end{tikzpicture}
\end{document}