20

Normally an edge drawn between two nodes starts and stops at the boundary of the nodes. How can one draw an edge to the center of a node?

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
Current result:

 \begin{tikzpicture}
  \node (0)              {};
  \node (1) [right of=0] {};
  \node (2) [above right of=1] {};
  \draw (0) -- (1);
  \draw (1) -- (2);
 \end{tikzpicture}

Desired result (looks like):

 \begin{tikzpicture}
  \draw (0,0) -- (1,0);
  \draw (1,0) -- (1.5,.5);
 \end{tikzpicture}
\end{document}

enter image description here

I want my TikZ code to be readable, so I first place the nodes with relative positions and then draw the edges. I created the desired result without using the relative placement of nodes. This is not an acceptable solution.

1 Answer 1

26

You can suffix an anchor to any node:

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
Current result:

 \begin{tikzpicture}
  \node (0)              {};
  \node (1) [right of=0] {};
  \node (2) [above right of=1] {};
  \draw (0.center) -- (1.center);
  \draw (1.center) -- (2.center);
 \end{tikzpicture}

\end{document}
1
  • Beautiful. I knew the answer should be simple. Thanks! Commented Jul 30, 2011 at 19:29

You must log in to answer this question.

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