# an edge connecting multiple nodes

I want to draw an edge that connects multiple nodes. I am able to achieve this using the ''to'' feature as shown in example below:

\documentclass[convert={density=300,size=1080x800,outext=.png}]{ standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\matrix (m)[column sep=.5in, row sep=.5in,  ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {};  \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {};  \\
};
\draw (r1c1)  to[<-]  (r2c1.center) to (r2c2.center) to (r1c2);
\end{tikzpicture}
\end{document}


The output looks as follows:

I am not able to change the property of the individual segment or connectors. For e.g. tikz discarded the directive for putting an arrow on the first leg of the connected. What I want to achieve to begin with is rounded corners.

Just to follow up along this line, below are three ways to achieve edge through multiple nodes

\documentclass[convert={density=300,size=1080x800,outext=.png{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\matrix (m)[column sep=.5in, row sep=.5in,  ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {};  \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {};  \\
};
\draw (r1c1)  edge  (r2c1.center) edge (r2c2.center) edge (r1c2);
\end{tikzpicture}

\begin{tikzpicture}
\matrix (m)[column sep=.5in, row sep=.5in,  ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {};  \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {};  \\
};
\draw (r1c1)  --  (r2c1.center) --  (r2c2.center) -- (r1c2);
\end{tikzpicture}
\end{document}


The output of which looks as follows:

Using edge doesn't work, but would have been the most flexible one.

• First of all matrices already have R1C1 like names out of the box, in your case those'd be (m-row-col), you can use (m-1-2) instead of (r1c2). Second, AFAIK to operators do not take arrow tips as Option. You can either split the path or use the markings decorations for the arrows. For rounded corners you can also split the path or, it's also possible to use a curve to but that's more of a Workaround than a solution. – Guilherme Zanotelli Nov 3 '16 at 14:48
• * For the rounded corners it may be possible to change in the middle of the path, but I'm not sure, I'd have to confirm it. – Guilherme Zanotelli Nov 3 '16 at 14:50
• @GuilhermeZ.Santos You need matrix of nodes or matrix of math nodes for the automatic naming though, right? And if you add a \node or something in a cell, then that node will not be given a name. – Torbjørn T. Nov 3 '16 at 15:00
• @TorbjørnT., right. Forgot to mention that. My Intention was to let the OP know of this automatic naming as he/she was doing manually... – Guilherme Zanotelli Nov 3 '16 at 15:07
• @GuilhermeZ.Santos Yes, rounded corners can be changed mid-path. – Emma Nov 3 '16 at 15:59

## 1 Answer

Like this?

\documentclass[tikz, border=3mm]{standalone}

\begin{document}
\begin{tikzpicture}
\matrix (m) [column sep=.5in, row sep=.5in,  ampersand replacement=\&]{
\node[] (r1c1) {}; \& \node[] (r1c2) {}; \& \node[] (r1c3) {};  \\
\node[] (r2c1) {}; \& \node[] (r2c2) {}; \& \node[] (r2c3) {};  \\
};
\draw[rounded corners,<-] (r1c1)  |- (r2c2.center) -- (r1c2);
\end{tikzpicture}
\end{document}


Addendum: Functions of nodes in matrix is not very clear. Concerning only the curve, the same result you can obtain with:

\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes, nodes in empty cells,
column sep=.5in, row sep=.5in]
{
&   &    \\
&   &    \\
};
\draw[rounded corners,<-] (m-1-1)  |- (m-2-2.center) -- (m-1-2);
\end{tikzpicture}
\end{document}

• This works. The node inside matrix cells are essentially textboxes. The auto matrix cell label is useful. Still would be good to know how to solve this using the "to" keyword. – Sandeep Nov 3 '16 at 15:50
• I have update the question with the other approaches. The edge option doesn't work. But is probably would have been most flexible as it would allow customization per segment. Is it possible wit h '--' or with 'to' keyword? – Sandeep Nov 3 '16 at 16:55
• You open a new question and it would be better to ask it as separate question. With it you will get more attention an more competent answers. Shortly and simplified: edges can connect only to coordinates (nodes), path[draw] or shortly \draw can cross many coordinates. So, \draw (r1c1) edge (r2c1.center) edge (r2c2.center) edge (r1c2); gives the same result as \draw (r1c1) edge (r2c1.center) (r1c1) edge (r2c2.center) (r1c1) edge (r1c2); as you notice. For more, the try read of TikZ & PGF manual. At least part III. – Zarko Nov 3 '16 at 17:06