2

My question might be really dumb, I'm new with tikz, and I might not understand well the difference between a draw and a node Here is my picture

\begin{tikzpicture}
\draw[thin,ball color=red] (0,0) circle(0.4ex) node(mX1){};
\draw[thin,ball color=white] (1,1)  circle(0.4ex) node[left] (X1){$X_1$};
\draw (X1)--(mX1);
\end{tikzpicture}

I'd like a link between my points, and not between the labels. I can't understand why the link is made on labels. My solution was this

\begin{tikzpicture}
\draw[very thin,ball color=red!50] (0,0) circle(0.4ex) node(mX1){};
\draw[thin,ball color=white,label=X1] (1,1)  circle(0.4ex) node{$X_1$};
\draw (X1)--(mX1);
\end{tikzpicture}

But here again, the link is made quite tangely (for me) Does anybody has any solution (and an explanation of what I missed)

Thanks a lot!

  • 1
    You are not making points with the (mX1) you are naming a node. If you just want to name the point, use coordinate (mX1). Also note that you can easily draw from the center of the node, just use mX1.center – daleif Sep 29 '15 at 10:38
3

I think you want something like the right figure below, left and middle figure are the result form your codes.

enter image description here

Command \draw just draws a path between provided coordinates, but it doesn't creates any labels for further reference. You need node or coordinate (an special kind of node) to assign labels to certain points on your canvas which can be later on used to draw lines between them or place new elements.

Your first command

\draw[thin,ball color=red] (0,0) circle(0.4ex) node(mX1){};

draw a red ball on coordinate (0,0) and also draws an invisible and empty node named mX1 on same coordinate. Change node (mX1) {} to node[draw] (mX1) {} to make it visible.

Second command

\draw[thin,ball color=white] (1,1)  circle(0.4ex) node[left] (X1){$X_1$};

does something similar, it draw a white ball on (1,1) but a node called X1 is placed to the left (1cm by default) of (1,1).

Line \draw (X1)--(mX1); goes form X1 border to mX1 border. And although X1 node is at origin, mX1 is not on white ball center, but to the left of it.

Proposed solution

\node[circle, very thin, ball color=red!50, minimum size=0.8ex, inner sep=0pt] (mX1) at (0,0) {};
\node[circle, very thin, ball color=white!50, minimum size=0.8ex, label=left:$X_1$, inner sep=0pt] (X1) at (1,1) {};

draws balls as circular nodes. This way X1 and mX1 make reference to balls center. And label X_1 is set as a label of second node. minimum size=0.8ex fixes ball diamenter if inner sep=0pt. This way line between nodes borders shows no separation from them.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[help lines] (0,0) grid (1,1);
\draw[thin,ball color=red] (0,0) circle(0.4ex) node(mX1){};
\draw[thin,ball color=white] (1,1)  circle(0.4ex) node[left] (X1){$X_1$};
\draw (X1)--(mX1);
\end{tikzpicture}

\begin{tikzpicture}
\draw[help lines] (0,0) grid (1,1);
\draw[very thin,ball color=red!50] (0,0) circle(0.4ex) node(mX1){};
\draw[thin,ball color=white,label=X1] (1,1)  circle(0.4ex) node{$X_1$};
\draw (X1)--(mX1);
\end{tikzpicture}

\begin{tikzpicture}
\draw[help lines] (0,0) grid (1,1);
\node[circle, very thin, ball color=red!50, minimum size=0.8ex, inner sep=0pt] (mX1) at (0,0) {};
\node[circle, very thin, ball color=white!50, minimum size=0.8ex, label=left:$X_1$, inner sep=0pt] (X1) at (1,1) {};
\draw (X1)--(mX1);
\end{tikzpicture}

\end{document}
2

Is this what you're trying to achieve?

Result of the snippet below

\documentclass[border=1cm, tikz]{standalone}
\begin{document}
\begin{tikzpicture}[
    point/.style={circle, draw, thin, inner sep=0.4ex}
]
    \node[point, ball color=red,   label=left:$mX_1$] (mX1) at (0, 0) {};
    \node[point, ball color=white, label=left:$X_1$]   (X1) at (1, 1) {};
    \draw (X1)--(mX1);
\end{tikzpicture}
\end{document}

Rather than drawing a circle manually with circle (0.4ex), I created a node shaped like a circle. The point style says that such a node should have its outline drawn, using a thin line. (In general, if you \draw something, it means "draw the outline of the stuff on this path".) It should be shaped like a circle, and have an inner sep (padding) of 0.4ex. Because this node doesn't have any text inside it, this padding acts like the radius.

Rather than create the labels manually using node [left] {$X_1$}, I used the label=... key to specify where and what I want the label to be. This stops me from accidentally calling my label (X1) instead of the circle (X1).

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.