I am trying to draw a sequence of nodes which I would like to connect.

The following path specification draws a triangle but connects the coordinates instead of the nodes at those coordinates.

\draw (0,0)
    +(90:1cm) node {1} to
    +(210:1cm) node {2} to
    +(330:1cm) node {3} to

What I would like instead would be something like the following code which connects the nodes and not the center positions stated in the path.

\draw (0,0)
    +(90:1cm) node[name=a]  {}
    +(210:1cm) node[name=b] {}
    +(330:1cm) node[name=c] {};
\foreach \from/\to in {a/b, b/c, c/a}
    \draw (\from) -- (\to);

Is there a direct way to do this without naming the nodes and drawing the lines manually?

edit: On the left is the first snippet and on the right the second, I want to have the right one: pathexample.png

  • naming the nodes is a convenient way! other ways is more complex I think
    – Black Mild
    May 7 at 12:23
  • I don't know if I understood properly your question, so are you looking for something like this? postimg.cc/WFZH113f/3ed0c296 May 7 at 12:41
  • @LukeTheWolf yes, that is exactly what I am looking for (and approximately what the second snippet produces)
    – Martin R
    May 7 at 13:29
  • @MartinR I have used a different structure, but if you just need the node connection it could be useful too. So tell me if you want me to post it anyway May 7 at 13:31
  • @LukeTheWolf I just added a picture of the problem. As long as it is simpler than naming the nodes and also scales to larger geometries, I am interested
    – Martin R
    May 7 at 13:39
\documentclass[tikz, border=2mm]{standalone}

\begin{tikzpicture}[every node/.style={circle, draw}]
\draw node (1) {1} --++(-60:2cm) node (2) {2} --++(180:2cm) node (3){3} (1)--(2)--(3)--(1);

enter image description here


Since I'm used to write automata, I found that was easier to draw a triangle in this way:

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
        scale = 1,transform shape]

  \node[state] (1) {$1$};
  \node[state] (2) [below left of=1] {$2$};
  \node[state] (3) [below right of=1] {$3$};

  \path [-] (1) edge (2)
        [-] (2) edge (3)
        [-] (1) edge (3);


It probably doesn't solve the problem the same way you were asking for, but as we discussed in the comment, this is how I would solve it.

In any case, you can take a cue from this and rewrite it in some other ways!


I guess you will get that naming the nodes is a convenient feature when you are more familiar with TikZ.

In the following, all nodes have no name.

enter image description here

\draw (90:\r)--(210:\r)--(-30:\r)--cycle;
(90:\r) node{1}
(210:\r) node{2}
(-30:\r) node{3};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.