16

Normally a edge drawn between two nodes starts and stops and 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 want 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.

20

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}
  • Beautiful. I knew the answer should be simple. Thanks! – Tyson Williams Jul 30 '11 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.