当我对边缘使用绝对位置时,我得到的箭头几乎相交。这是我的代码。请帮忙。
\begin{tikzpicture} [
node distance = 2cm and 0.8cm,
>=stealth,
scale=0.8,
transform shape
]
\node[block] at (2,3) (Incompetent Reflux Mechanism){Incompetent Lower esophageal sphincter};
\node[block] at (2,0) (Gastric content into esophagus and beyond){Gastric content into esophagus and beyond};
\node[block] at (-2, -3) (Symptoms){Symptoms};
\node[block] at (6, -3)(Mucosal damage){Mucosal damage};
\node at (2,-3){and or};
\begin{scope}[cyan!40!black]
\draw[->] (2,3) -- (2,0);
\draw[->] (2,0) -- (-2,-3);
\draw[->] (2,0) -- (6,-3);
\end{scope}
\end{tikzpicture}
\end{frame}
答案1
一般来说,node
s 的写法如下:
\node[<options>] at (<x>,<y>) (<label>) {<content>};
您已经label
绘制了节点,但这些标签太长了。把它们缩短:(Mechanism)
而不是(Incompetent Reflux Mechanism)
现在您可以借助这些标签绘制箭头:
\draw[->] (Mechanism) -- (Gastric);
Mechanism
将在标有和 的节点之间绘制一个箭头Gastric
。
完整代码:
\documentclass[tikz,border=10pt]{standalone}
\tikzset{block/.style ={rectangle,draw}
}
\begin{document}
\begin{tikzpicture} [
node distance = 2cm and 0.8cm,
>=stealth,
scale=0.8,
transform shape
]
\node[block] at (2,3) (Mechanism){Incompetent Lower esophageal sphincter};
\node[block] at (2,0) (Gastric){Gastric content into esophagus and beyond};
\node[block] at (-2, -3) (Symptoms){Symptoms};
\node[block] at (6, -3) (Mucosal){Mucosal damage};
\node at (2,-3){and or};
\begin{scope}[cyan!40!black]
\draw[->] (Mechanism) -- (Gastric);
\draw[->] (Gastric.south) -- (Symptoms.north);
\draw[->] (Gastric.south) -- (Mucosal.north);
\end{scope}
\end{tikzpicture}
\end{document}
你也可以制作箭头来转向
\draw[->] (Gastric.south) -- ++(0,-1) -| (Symptoms.north);
(Gastric.south) -- ++(0,-1)
从 向下 画一条线Gastric.south
,长度为 1cm,并-| (Symptoms.north);
画一个向 弯曲的箭头Symptoms.north
。
\documentclass[tikz,border=10pt]{standalone}
\tikzset{block/.style ={rectangle,draw}
}
\begin{document}
\begin{tikzpicture} [
node distance = 2cm and 0.8cm,
>=stealth,
scale=0.8,
transform shape
]
\node[block] at (2,3) (Mechanism){Incompetent Lower esophageal sphincter};
\node[block] at (2,0) (Gastric){Gastric content into esophagus and beyond};
\node[block] at (-2, -3) (Symptoms){Symptoms};
\node[block] at (6, -3) (Mucosal){Mucosal damage};
\node at (2,-3){and or};
\begin{scope}[cyan!40!black]
\draw[->] (Mechanism) -- (Gastric);
\draw[->] (Gastric.south) -- ++(0,-1) -| (Symptoms.north);
\draw[->] (Gastric.south) -- ++(0,-1) -| (Mucosal.north);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
您可以在标记的两个节点之间画线,而不是两个坐标之间画线。
\begin{tikzpicture} [
node distance = 2cm and 0.8cm,
>=stealth,
scale=0.8,
transform shape
]
\node(a1) at (0,0) {Hello};
\node(a2) at (2,0) {World};
\draw[->] (a1) -- (a2);
\end{tikzpicture}