请问如何将箭头添加到使用|-
符号链定义的边上?还是我只需要定义多个\draw
调用?
在下图中,我还希望箭头进入节点2
和3
。谢谢。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node[draw] (1) {1};
\node[draw, below=of 1] (2) {2};
\node[draw, below=of 2] (3) {3};
\node[draw, below=of 3] (4) {4};
\draw[red, {Latex[length=5mm]}-] (1.east) -- +(0:20mm) |- (2.east)
-- +(0:20mm) |- (3.east)
-- +(0:20mm) |- (4.east);
\end{tikzpicture}
\end{document}
答案1
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node[draw] (1) {1}++(0:20mm)coordinate(aux);
\node[draw, below=of 1] (2) {2};
\node[draw, below=of 2] (3) {3};
\node[draw, below=of 3] (4) {4};
\draw[red, {Latex[length=5mm]}-] (1) -|(aux);
\draw[red, {Latex[length=5mm]}-] (2)-|(aux);
\draw[red, {Latex[length=5mm]}-] (3)-|(aux);
\draw[red, ] (4)-|(aux);
\end{tikzpicture}
\end{document}
foreach
循环得到相同的结果
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node[draw] (1) {1}++(0:20mm)coordinate(aux);
\foreach \X [count=\xi]in {2,3,4}{%
\node[draw, below=of \xi] (\X) {\X};
}
\foreach \Y in {1,2,3}{
\draw[red, {Latex[length=5mm]}-] (\Y) -|(aux);
\draw[red, ] (4)-|(aux);
}
\end{tikzpicture}
\end{document}
答案2
这是使用 TikZ 的另一种方法。根据需要更改\a
和的值。该选项使框垂直对齐。\b
minimum size=5mm
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\a{2} \def\b{.65}
\foreach \i in {1,...,4}{
\path (0,-\i*\b) node[draw,red,rounded corners,minimum size=5mm] (A\i) {\i};
\draw[stealth-] (A\i.east)-|(\a,-\b);
}
\end{tikzpicture}
\end{document}