1

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?

1

1 Answer 1

5

Something like this?

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

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

\begin{scope}[xshift=2cm]
\node[circle, draw, label=A] (A) at (0,1) {};
\node[circle, draw, label=B] (B) at (1,0) {};
\draw[<->] (A.center) -- (B.center);
\end{scope}
\end{tikzpicture}
\end{document}

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).

3
  • How do you position the label? For example, below? Mar 22, 2018 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. Mar 22, 2018 at 9:54
  • @Chrystomath: No, just write label=below:B.
    – Ignasi
    Mar 22, 2018 at 10:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .