两个节点之间的路径垂直

两个节点之间的路径垂直

我希望箭头在节点之间垂直。我该怎么做?目前,它是倾斜的,在节点的 south.center 和 north.center 之间。

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes,calc}
\begin{document}
\tikzstyle{block} = [rectangle, fill=red!20,
text width=.23\textwidth, text centered, rounded corners, node distance=1cm]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[thick,scale=1, every node/.style={scale=0.9}]
    \node[block]at (0,0) (init) {Hello};
    \node[block, below of =init,xshift=1cm](init2) {Hello};
    \path[line](init)--(init2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

注意:请注意,init2 的 xshift 是为了显示情况。我必须调整路径。

答案1

在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes,calc}
\begin{document}
    \tikzstyle{block} = [rectangle, fill=red!20,
    text width=.23\textwidth, text centered, rounded corners, node distance=1cm]
    \tikzstyle{line} = [draw, -latex']
    \begin{tikzpicture}[thick,scale=1, every node/.style={scale=0.9}]
        \node[block]at (0,0) (init) {Hello};
        \node[block, below of =init,xshift=1cm](init2) {Hello};
        \path[line](init.south)--(init.south|-init2.north);
    \end{tikzpicture}
\end{document}

答案2

目前尚不清楚,你的箭头应该是什么样子:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 8mm and 2mm,
  arr/.style = {semithick, -Straight Barb},
block/.style = {fill=red!20, rounded corners, 
                text width=.23\textwidth, align=center}
                        ]
\node (init1) [block]    {Hello};
\node (init2) [block, below=of init1, xshift=3em] {Hello};
%
\draw[arr] (init1) -- (init1 |- init2.north);    % this
\draw[arr, gray, very thick, semitransparent] (init1.south) -- ++ (0,-0.3) -| (init2); % or this?
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容