[Tex/LaTex] How to make arrow point to node in Tikz

tikz-arrowstikz-pgf

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?

Best Answer

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

Related Question