# tikz: wonky spacing even with “on grid”

I'm a newbie making a simple flow diagram using relative positioning and on grid. My diagram is simple, so I expected everything to line up easily. But I'm getting this:

I'm trying to draw arrows from the right-most nodes to some invisible placeholder nodes on the right margin (using [coordinate]), and I'm lining those up relative to the center line. But something is wonky.

Am I missing something basic? My code:

\documentclass[letterpaper,11pt,reqno]{amsart}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.geometric}

\begin{document}
\begin{tikzpicture}[nodes = {draw,font=\ttfamily\footnotesize, inner sep = 1pt}, on grid]

% nodes on the main line + coordinate placeholders
\node [circle] (1) {1};
\node [circle, right=10mm of 1] (2) {2};
\node [coordinate, right=10mm of 2] (3g) { };
\node [circle, right=10mm of 3g] (6) {6};
\node [coordinate, right=10mm of 6] (7g) { };
\node [coordinate, right=10mm of 7g] (8g) { };
\node [coordinate, right=10mm of 8g] (9g) { };

% other nodes
\node [circle, below=1cm of 3g] (3) {3};
\node [circle, below=1cm of 7g] (7) {7};
\node [circle, above=1cm of 8g] (8) {8};
\node [circle, below=2cm of 9g] (9) {9};

% right edge coordinate placeholders
\node [coordinate, right=10mm of 9g] (edge) { };
\node [coordinate, above=1cm of edge] (edge_above) { };
\node [coordinate, below=1cm of edge] (edge_below1) { };
\node [coordinate, below=2cm of edge] (edge_below2) { };

% paths
\path[draw]
(1) -- (2)
(2) -- (6)
(2) |- (3)
(3) -- (7)
(7) |- (9)
(6) |- (8);

% right arrows
\path[draw, ->]    (8) -> (edge_above);
\path[draw, ->]    (6) -> (edge);
\path[draw, ->]    (7) -> (edge_below1);
\path[draw, ->]    (9) -> (edge_below2);
\end{tikzpicture}
\end{document}


I suppose there could be some improvements to your scheme, but to fix your problem, here's the solution: delete the coordinates, and rewrite your last arrows like this:

\draw[->] (8) -- ++ (2.5,0) coordinate (eight);
\draw[->] (6) -- (6-|eight);
\draw[->] (7) -- (7-|eight);
\draw[->] (9) -- (9-|eight);


Basically, the first arrow (top one), goes on for 2.5cm and establishes a coordinate eight at that point. Then, using the TikZ operator -| we can draw arrows from the other nodes that go on, horizontally (-) until they reach the same vertical position of eight (|) and there, they stop.

Here's the result:

• Thanks for explaining that in a way that helps me understand how to use relative positioning properly! I see what you mean by "improvements to your scheme..." But shouldn't the original method still work in theory? – gogurt Jan 12 '16 at 21:22
• @gogurt Not really. The only straight one you had was the line starting from 6 and it was the only one that said right=10mm of 9g. The others were placed using this one, with above or below. But even if the measurement was right, you weren't taking into account the sizes related to the nodes: text height, inner and outer sep... – Alenanno Jan 12 '16 at 21:29
• OK, I see. I'll spend some more time with the manual. Thanks again. – gogurt Jan 12 '16 at 21:30
• @gogurt Try this, set the node options like inner sep=0, outer sep=0, minimum size=5mm. Now that circle is exactly 5mm big. That means that its "center" is 2.5mm. Then you can establish the coordinate like above=1.25cm of edge. Now the line will be straight. But this calculation renders Latex pointless, because the good thing is to have the code do its calculations for you. :) – Alenanno Jan 12 '16 at 21:33