# Are there any differences between a “newly defined” path and a path using predefined nodes?

I am not sure how I should phrase my question.

consider the following example

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\node[inner sep=0] at (0,0) (a) {};
\node[inner sep=0] at (3,0) (b) {};
\node[inner sep=0] at (3,3) (c) {};
\node[inner sep=0] at (0,3) (d) {};

\draw[fill=black!10] (a) -- (b) -- (c) -- (d) -- cycle;
\draw[fill=black!30] (b) -- (6,0) -- (6,3) -- (c) -- cycle;

\end{tikzpicture}
\end{document}


Only the second \draw command gets filled. In the first case not even the cycle operation works.

As far as I checked, when you use consecutive (predefined) nodes in a path (e.g. (a) -- (b)) then the filling operation doesn't work correctly. If you define new coordinates in the path (e.g. (6,0) -- (6,3)) then there are no problems.

Is this behavior normal?

-

This happens because when you specify just the node name, without an anchor, the border of the node is used to draw the line. Even with inner sep=0pt, this point will be different depending on the direction of the line to be drawn. In order to achieve the desired result, you should explicitly use an anchor (like center), or define coordinate nodes instead:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\node[inner sep=0] at (0,0) (a) {};
\node[inner sep=0] at (3,0) (b) {};
\node[inner sep=0] at (3,3) (c) {};
\node[inner sep=0] at (0,3) (d) {};
\coordinate (A) at (7,0);
\coordinate (B) at (10,0);
\coordinate (C) at (10,3);
\coordinate (D) at (7,3);

\draw[fill=black!10] (a.center) -- (b.center) -- (c.center) -- (d.center) -- cycle;
\draw[fill=black!10] (A) -- (B) -- (C) -- (D) -- cycle;
\draw[fill=black!30] (b.center) -- (6,0) -- (6,3) -- (c.center) -- cycle;

\end{tikzpicture}
\end{document}


-
+1 I was just typing the same answer ;-) The border is also dependent on outer sep which is .5\pgflinewidth by default. But even when this one is set to zero the fill operation doesn't work. – Martin Scharrer May 22 '11 at 11:47
Thank you both! – pmav99 May 22 '11 at 12:11

After reading Jake's answer, I found the relevant section in the tikz manual (v 2.10 section 16.2.1 "Predefined Shapes")

An alternative syntax, would be to use the node shape coordinate:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\node[coordinate] at (0,0) (a) {};
\node[coordinate] at (3,0) (b) {};
\node[coordinate] at (3,3) (c) {};
\node[coordinate] at (0,3) (d) {};

\draw[fill=black!10] (a) -- (b) -- (c) -- (d) -- cycle;
\draw[fill=black!30] (b) -- (6,0) -- (6,3) -- (c) -- cycle;

\end{tikzpicture}
\end{document}

-
\coordinate is shorthand for \node[coordinate]; so the two expressions are equivalent, but in my opinion using \coordinate is clearer, because you don't need the empty pair of brackets (a coordinate node can't have a label text anyway). – Jake May 22 '11 at 12:42
@Jake, yeah i know I just posted for reference, in case somebody wants to check the manual. – pmav99 May 22 '11 at 13:02