Newbie Tikz question: I want to draw an arrow from a bullet to another bullet, with the arrow starting from and aiming to the bullets' centres, and I want the bullets labelled. This is my attempt:

\fill(0,1) circle (2pt) node[above] (A) {1}; \fill(1,0) circle (2pt) node[below] (B) {2}; \draw[-latex] (A) edge (B)

The problem with it is that the arrow is centred somewhere between the bullet and the label. I think I can see why it is happening: A is a node above the circle, so the arrow is starting from there. So perhaps the question should be: How do I turn the circle into a node, and how to label it?


Something like this?


\node[circle, draw, label=A] (A) at (0,1) {};
\node[circle, draw, label=B] (B) at (1,0) {};
\draw[<->] (A) -- (B);

\node[circle, draw, label=A] (A) at (0,1) {};
\node[circle, draw, label=B] (B) at (1,0) {};
\draw[<->] (A.center) -- (B.center);

enter image description here

A node can take several forms. Default one is rectangle but you can also use circle. Charging shapes library you can get other aspects: ellipse, triangle, arrow, regular polygon, ...

If want to add a label above the node, you can use label option. If you want some text inside the node, write the text inside node's contents part: {}.

By deafult lines (or arrows) between nodes will stop at node's borders: (A)--(B). If you want to explicitly join their centers use the specific anchor: (A.center)--(B.center).

  • How do you position the label? For example, below? – Chrystomath Mar 22 '18 at 9:39
  • Ok got it, thanks! You need to add a new node \node[below]at(B.south){2} to position the label correctly. – Chrystomath Mar 22 '18 at 9:54
  • @Chrystomath: No, just write label=below:B. – Ignasi Mar 22 '18 at 10:37

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.