我正在使用 TikZ 绘制图表。弯曲的箭头在方框之间映射不正确。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\tikzset{
%Define standard arrow tip
>=stealth',
%Define style for boxes
punkt/.style={
rectangle,
rounded corners,
draw=black, very thick,
text width=6.5em,
minimum height=2em,
text centered},
plain/.style={
rectangle,
rounded corners,
draw=white, very thick,
text width=6.5em,
minimum height=2em,
text centered},
% Define arrow style
pil/.style={
->,
thick,
shorten <=2pt,
shorten >=2pt,}
}
\begin{document}
\begin{tikzpicture}
\node[punkt] (a) {AAAAA};
\node[punkt, inner sep=5pt, right=0.5 of a] (b) {BBBBBB BBBBB}
edge[pil,<-] (a.east);
\node[plain, inner sep=5pt, right=0.5 of b] (dummy) {};
\node[punkt, inner sep=5pt, above=0.5 of dummy] (b1) {BBBBBB BBBBB1}
edge[pil, <-, bend right=45] (b.north);
\node[punkt, inner sep=5pt, below=0.5 of dummy] (b2) {BBBBBB BBBBB2}
edge[pil, <-, bend left=45] (b.south);
\node[plain, inner sep=5pt, right=0.5 of dummy] (dummy2) {};
\node[punkt, inner sep=5pt, above=0.5 of dummy2] (c1) {CCCCCC CCCC1}
edge[pil,<-] (b1.east);
\node[punkt, inner sep=5pt, below=0.5 of dummy2] (c2) {CCCCCC CCCC2}
edge[pil,<-] (b2.east);
\node[punkt, inner sep=5pt, right=0.5 of dummy2] (d) {DDDDDD DDDD}
edge[pil, <- , bend right=45] (c1.east)
edge[pil, <- , bend left=45] (c2.east);
\end{tikzpicture}
\end{document}
此代码生成以下图片。
有没有办法让它们更漂亮?
答案1
有一件事通常没有得到足够的重视,那就是除非你正在加载库,否则带箭头的曲线路径会变形bending
。无论你是否真的bend
在箭头上添加了键,情况都是如此,请参阅 pgfmanual v3.1.5 第 204 页
但我也会弯曲箭头。而且我会选择另一种弯曲箭头的方式:使用in
andout
语法。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending,positioning}
\tikzset{
%Define standard arrow tip
>={Stealth[bend]},
%Define style for boxes
punkt/.style={
rectangle,
rounded corners,
draw=black, very thick,
text width=6.5em,
minimum height=2em,
text centered},
plain/.style={
rectangle,
rounded corners,
draw=white, very thick,
text width=6.5em,
minimum height=2em,
text centered},
% Define arrow style
pil/.style={
->,
thick,
shorten <=2pt,
shorten >=2pt,}
}
\begin{document}
\begin{tikzpicture}
\node[punkt] (a) {AAAAA};
\node[punkt, inner sep=5pt, right=0.5 of a] (b) {BBBBBB BBBBB}
edge[pil,<-] (a.east);
\node[plain, inner sep=5pt, right=0.5 of b.east] (dummy) {};
\node[punkt, inner sep=5pt, above=0.5 of dummy] (b1) {BBBBBB BBBBB1}
edge[pil, <-, out=180,in=60] (b.north);
\node[punkt, inner sep=5pt, below=0.5 of dummy] (b2) {BBBBBB BBBBB2}
edge[pil, <-, out=180,in=-60] (b.south);
\node[plain, inner sep=5pt, right=0.5 of dummy] (dummy2) {};
\node[punkt, inner sep=5pt, above=0.5 of dummy2] (c1) {CCCCCC CCCC1}
edge[pil,<-] (b1.east);
\node[punkt, inner sep=5pt, below=0.5 of dummy2] (c2) {CCCCCC CCCC2}
edge[pil,<-] (b2.east);
\node[punkt, inner sep=5pt, right=0.5 of dummy2] (d) {DDDDDD DDDD}
edge[pil, <- , out=120,in=0] (c1.east)
edge[pil, <- , out=-120,in=0] (c2.east);
\end{tikzpicture}
\end{document}
答案2
您可能喜欢:在路径有圆角的地方edge[bend ...]
使用\draw (x) |- (y)
或\draw (x) -| (y)
或:\draw (x) -| (y)
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 5mm,
punkt/.style = {draw, very thick, rounded corners,
text width=6.5em, minimum height=2em,
inner sep=5pt, align=center},
every path/.style = {draw, rounded corners=6mm, stealth-,
thick, shorten <=2pt, shorten >=2pt},
]
\node[punkt] (a) {AAAAA};
\node[punkt, right=of a] (b) {BBBBBB BBBBB} edge (a);
\node[punkt, above right=of b] (c1) {BBBBBB BBBBB1};
\draw (c1) -| (b);
\node[punkt, below right=of b] (c2) {BBBBBB BBBBB2};
\draw (c2) -| (b);
\node[punkt, right=of c1] (d1) {CCCCCC CCCC1} edge (c1);
\node[punkt, right=of c2] (d2) {CCCCCC CCCC2} edge (c2);
\node[punkt, below right=of d1] (e) {CCCCCC CCCC1};
\draw (e) |- (d1);
\draw (e) |- (d2);
\end{tikzpicture}
\end{document}