TikZ: draw lines connecting border of shapes

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}

enter image description here

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}

enter image description here

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.


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}

output

Tags:

Tikz Pgf