user4284784
user4284784

Reputation:

How to connect nodes with TikZ chain like this example?

After reading How to connect nodes with TikZ?,I am thinking about how to convert below simple example to use TiKz chain.

Current 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}

Current output:

enter code here

I wish to use chain library to do it but still not find right way. The node position should not change and the connection line style should the same.

Upvotes: 2

Views: 5067

Answers (1)

lucky1928
lucky1928

Reputation: 8905

From this example, it use chain for straight line node connection but use \draw command to draw no-straight line path.

So I think it's not proper to use chain for current tasks. Or you can just create two invisible coordinate then connect it with chain (too complicated, right?).

\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

Upvotes: 0

Related Questions