如何用这个例子连接节点和TikZ链?

时间:2015-03-15 15:49:43

标签: chain tikz

阅读How to connect nodes with TikZ?后,我正在考虑如何将以下简单示例转换为使用TiKz链。

目前的MWE:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,positioning,calc}

\tikzset{
    block/.style={draw,text width=2em,minimum height=1em,align=center},
    arrow/.style={->}
}
\newcommand\connect[2]{\path[draw,arrow] (#1) |- ($(#1)!1/2!(#2)$) -| (#2)}

\begin{document}
\begin{tikzpicture}[>=stealth']
    \node[block] (N1) {N1};
    \node[block,below=1cm of N1,xshift=-1cm] (N2) {N2};
    \connect{N1}{N2};
\end{tikzpicture}
\end{document}

当前输出:

enter code here

我希望使用链库来做但仍然找不到正确的方法。节点位置不应更改,连接线样式应相同。

1 个答案:

答案 0 :(得分:0)

this示例,它使用链进行直线节点连接,但使用\ draw命令绘制非直线路径。

所以我认为将链用于当前任务是不合适的。或者你可以创建两个不可见的坐标然后用链连接(太复杂,对吧?)。

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,chains,positioning,scopes,quotes}

\tikzset{
    block/.style={draw,text width=2em,minimum height=1em,align=center},
    arrow/.style={->}
}

\begin{document}
    \begin{tikzpicture}[>=stealth']
    {[start chain]
        \node[block,on chain] (N1) {N1};
        \node[block,on chain,join=by {arrow},below=1cm of N1,xshift=-1cm] (N2) {N2};
    }
    \end{tikzpicture}
\end{document}

enter image description here