这是我的 MWE:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,calc,shapes,positioning,shapes.misc}
\tikzset{terminal/.style={,
% The shape:
rectangle,minimum size=6mm,rounded corners=3mm,
% The rest
very thick,draw=black!50,
top color=white,bottom color=black!20,
font=\ttfamily},
nonterminal/.style={
% The shape:
rectangle,
% The size:
minimum size=6mm,
% The border:
very thick,
draw=red!50!black!50, % 50% red and 50% black,
% and that mixed with 50% white
% The filling:
top color=white, % a shading that is white at the top...
bottom color=red!50!black!20, % and something else at the bottom
% Font
font=\itshape
}
}
\begin{document}
\begin{tikzpicture}[node distance=5mm and 5mm,
skip loop/.style={to path={-- ++(0,-.5) -| (\tikztotarget)}}]
\node (first) [terminal] {First};
\node (second) [terminal,above=of first] {Second};
\node (fourth) [terminal,above=of second] {Fourth};
\node (third) [terminal,below=of first] {Third};
\node (fifth) [terminal,below=of third] {Fifth};
\node (compar1) [terminal,right=of first] {compar1};
\node (compar2) [terminal,right=of compar1] {compar2};
\node (compar3) [terminal,right=of compar2] {compar3};
\node (compar4) [terminal,right=of compar3] {compar4};
\path (first) edge[->] (compar1) % simple edges
(second) edge[->] (compar1)
(third) edge[->] (compar1)
(fourth) edge[->] (compar1)
(fifth) edge[->] (compar1)
(compar1) edge[<-](compar2)
(compar2) edge[<-](compar3)
(compar3) edge[<->](compar4)
% straight edges
(first) edge[-] (second)
(first) edge[-] (third)
(second) edge[-] (fourth)
(third) edge[-] (fifth);
\end{tikzpicture}
\end{document}
答案1
例如这样:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,calc,shapes,positioning,shapes.misc}
\tikzset{terminal/.style={,
% The shape:
rectangle,minimum size=6mm,rounded corners=3mm,
% The rest
very thick,draw=black!50,
top color=white,bottom color=black!20,
font=\ttfamily},
nonterminal/.style={
% The shape:
rectangle,
% The size:
minimum size=6mm,
% The border:
very thick,
draw=red!50!black!50, % 50% red and 50% black,
% and that mixed with 50% white
% The filling:
top color=white, % a shading that is white at the top...
bottom color=red!50!black!20, % and something else at the bottom
% Font
font=\itshape
}
}
\begin{document}
\begin{tikzpicture}[node distance=5mm and 5mm,
skip loop/.style={to path={-- ++(0,-.5) -| (\tikztotarget)}}]
\node (first) [terminal] {First};
\node (second) [terminal,above=of first] {Second};
\node (fourth) [terminal,above=of second] {Fourth};
\node (third) [terminal,below=of first] {Third};
\node (fifth) [terminal,below=of third] {Fifth};
\node (compar1) [terminal,right=of first] {compar1};
\node (compar2) [terminal,right=of compar1] {compar2};
\node (compar3) [terminal,right=of compar2] {compar3};
\node (compar4) [terminal,right=of compar3] {compar4};
\path (first) edge[->] (compar1) % simple edges
(second) edge[->,out=0,in=160] (compar1)
(third) edge[->,out=0,in=200] (compar1)
(fourth) edge[->,out=0,in=140] (compar1)
(fifth) edge[->,,out=0,in=220] (compar1)
(compar1) edge[<-](compar2)
(compar2) edge[<-](compar3)
(compar3) edge[<->](compar4)
% straight edges
(first) edge[-] (second)
(first) edge[-] (third)
(second) edge[-] (fourth)
(third) edge[-] (fifth);
\end{tikzpicture}
\end{document}
使用in
和out
可以指定边缘的出口和入口角度。0
表示零度,位于节点的右侧;90
表示节点的顶部。
上述代码产生的结果: