将箭头添加到路径序列中

将箭头添加到路径序列中

请问如何将箭头添加到使用|-符号链定义的边上?还是我只需要定义多个\draw调用?

在下图中,我还希望箭头进入节点23。谢谢。

在此处输入图片描述


\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和的值。该选项使框垂直对齐。\bminimum 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}

相关内容