Why does tikz cycle not work and why are these two sets of nodes different?
By bare nodes node names are meant. When you use the node name, TikZ tries to be smart and checks where the target is and calculates the point on its shape border. Same goes for the target.
So essentially you are creating 3 separate paths and the last one is a line hence when used with cycle you get the last line printed twice. Because cycle only draws back to the last continuous path starting point.
If you use actual coordinates instead of node names such as (A.center)
it works again.
\begin{tikzpicture}
\node at (0,0) (A) {A};
\node at (0,1) (B) {B};
\node at (1,0) (C) {C};
\draw (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
In this case you are placing some nodes centered on certain coordinates. Every node is, by default, a rectangle around its contents. It has some inner sep
between its contents and border. These borders are not drawn by default, but they exist.
When you write \draw (A) -- (B) -- (C) -- cycle;
, Tikz tries to join node's centers but stopping lines on nodes' borders. Therefore you see two disjoint lines, one between A
and B
and another from B
to C
, but as it's not possible to close the cycle, because you don't have a continous path, there is no line between C
and A
.
\begin{tikzpicture}
\draw (0,0) node (A) {A} --
(0,1) node (B) {B} --
(1,0) node (C) {C} --
cycle ;
\end{tikzpicture}
In this case as percusse
already explained, your are drawing a closed path between certain coordinates
\draw (0,0) -- (0,1) -- (1,0) -- cycle ;
and supperposing node on it. It's a different command which produces a different solution.