# With TikZ, How do I use a labeled coordinate that's inside a node? [closed]

In the following diagram, I'm trying to draw a line from the center of the red dot (inside the blue node) to the green node. The coordinate of the red dot is labeled "thepoint", so this should be easy. However the line seems to go from the origin (0,0) of the blue node instead...

Does anyone know what I'm doing wrong? How can I refer to a labeled coordinate that's inside a node? (Or is there a better way of doing this?)

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

%first node
\node [fill=blue!20, matrix] (firstNode)
{
%some dots
\fill[red] coordinate (thepoint) (0.4,0.2) circle (3pt);
\fill[black] (0.0,0.2) circle (3pt);
\fill[black] (0.0,-0.2) circle (3pt);\\
};

%another node
\node[fill=green!20](anotherNode) at (3,0) {2nd node};

%the line
\draw[-latex] (thepoint) to [out=30,in=180] (anotherNode.west);

\end{tikzpicture}
\end{document}


Thanks!

EDIT: Answered my own question! (sigh...)

I had a small (but important) syntax mistake. The correct way to define the coordinate is:

\fill[red] (0.4,0.2) coordinate (thepoint) circle (3pt);

-
Welcome to TeX.sx, Spacecookies! Good job at finding the error yourself! We'll probably close this question so it is removed from the "Unanswered" list. Looking forward to seeing you around! – Jake Sep 19 '11 at 2:41
And you can answer your question and accept it. – Leo Liu Sep 19 '11 at 6:32

## closed as too localized by Jake, Alan Munn, Caramdir, Joseph Wright♦Dec 5 '11 at 20:06

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

I must admit that when I first read the question, my reaction was "Don't do that!".

The "that" which I was thinking of was putting stuff inside a node. But then I saw that you were actually using a matrix node which is explicitly designed for putting stuff inside! However, once I'd seen that you were using a matrix node, I was puzzled as to why you were giving explicit coordinates to the entries as the matrix is meant to deal with all the alignment.

So although you've answered your immediate question, I'd like to offer a couple of reformulations of your code which make use of the matrix alignment. The first is your code (with your correction). The second simply uses the same basic code but uses the matrix to put the sub-objects in their place. The third replaces the sub-objects by nodes. The difference here is subtle: it allows you to put your style options in a different place (and thus organise them slightly differently, and make it easier to modify them all in one go), and the base of the arrow is now the border of the circle, not its centre. To restore it to its centre, make the reference firstNode-1-2.center. Once again, this gives greater flexibility.

Here's the code. The TikZ libraries are only needed for the last version.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix,shapes.geometric}
\begin{document}
\begin{tikzpicture}

%first node
\node [fill=blue!20, matrix] (firstNode)
{
%some dots
\fill[red] (0.4,0.2) coordinate (thepoint) circle (3pt);
\fill[black] (0.0,0.2) circle (3pt);
\fill[black] (0.0,-0.2) circle (3pt);\\
};

%another node
\node[fill=green!20](anotherNode) at (3,0) {2nd node};

%the line
\draw[-latex] (thepoint) to [out=30,in=180] (anotherNode.west);

\end{tikzpicture}

\begin{tikzpicture}

%first node
\matrix [fill=blue!20,row sep={0.4cm,between origins},column sep={0.4cm,between origins}] (firstNode)
{
\fill[black] circle (3pt); &
\fill[red] circle (3pt) coordinate (thepoint); \\
\fill[black] circle (3pt);\\
};

%another node
\node[fill=green!20](anotherNode) at (3,0) {2nd node};

%the line
\draw[-latex] (thepoint) to [out=30,in=180] (anotherNode.west);

\end{tikzpicture}

\begin{tikzpicture}

%first node
\matrix [
matrix of nodes,
every cell/.style={
ellipse,
minimum size=6pt,
inner sep=0pt,
},
fill=blue!20,
row sep={%
0.4cm,%
between origins,%
},
column sep={%
0.4cm,%
between origins,%
}
] (firstNode)
{
|[fill=black]| {} &
|[fill=red]| {} \\
|[fill=black]| {} \\
};

%another node
\node[fill=green!20](anotherNode) at (3,0) {2nd node};

%the line
\draw[-latex] (firstNode-1-2) to [out=30,in=180] (anotherNode.west);

\end{tikzpicture}
\end{document}


-