# TikZ: draw lines connecting border of shapes

Being new to TikZ, I am trying to draw several (labeled) circles which are connected by lines. In its simplest form, I am doing this via

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\draw (0,0) circle [radius=0.5] node (A) {A};
\draw (2,2) circle [radius=0.5] node (B) {B};
\draw (A) -- (B);
\end{tikzpicture}

\end{document}


However, the connecting line reaches inside the circles which I don't want it to do:

How do I make the line reach only from border to border?

• you can make those circles as nodes \node[draw,circle,minimum size=1cm] at (2,2) {B}; etc. – percusse Nov 13 '14 at 11:55

As percusse commented you can draw circular nodes.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node[circle,draw, minimum size=1cm] (A) at  (0,0) {A};
\node[circle,draw, minimum size=1cm] (B) at  (2,2)  {B};
\draw (A) -- (B);
\end{tikzpicture}

\end{document}


Your code also works, but the problem is with how you've defined the nodes. I've added draw,red style to better see what happens:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\draw (0,0) circle [radius=0.5] node[draw,red] (A) {A};
\draw (2,2) circle [radius=0.5] node[draw,red] (B) {B};
\draw (A) -- (B);
\end{tikzpicture}

\end{document}


As you can see, you are drawing two circles with rectangular nodes inside that are not drawn. And command \draw (A)--(B) works correctly, it stops drawing on node boundaries but not on circles boundaries as you expected.

• +1 for explaining why the original code gives an undesired result. – Matthew Leingang Nov 13 '14 at 20:26
• Is\path (0,0) node [circle,draw,minimum size=1cm] (A) {A} ; identical to \node[circle,draw,minimum size=1cm] (A) at (0,0){A}; ? – Money Oriented Programmer Aug 17 '17 at 14:33
• @SinglePackAbs Yes, it is. You can even omit (0,0) because is the default starting coordinate: \node[circle,...] (A) {A}; – Ignasi Aug 18 '17 at 9:11

A PSTricks solution using the pst-node package:

\documentclass{article}

\usepackage{pst-node}

\begin{document}

\begin{pspicture}(-0.35,-0.35)(3,3) % adjust the bounding box manually according to the contents of the pspicture environment
\cnodeput(0.5,0.5){A}{Mammal}
\cnodeput(2.5,2.5){B}{Fish}
\ncline{A}{B}
\end{pspicture}

\end{document}