# Node positioning relative to 2 other nodes

I'm wanting to align/position a node relative to 2 others. Basically I'd like everything to be in rows and columns (whose is determined by the largest member). In this specific instance, I'd like node j to be centered on the intersection of the red and blue lines in the picture below. This would cause the 2 decision diamonds to be evenly spaced like f and g.

\documentclass{article}

\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, draw,
text centered,
minimum height=3em
]
\tikzstyle{test}    = [ diamond,
draw,
shape aspect=2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action}  = [ rectangle, draw,
text width=8em,
inner sep = 5pt,
minimum height=5em
]

\begin{tikzpicture}[node distance = 1.25em, align = flush center, font = \small]
% Place nodes
\node [test] (f) {fLorem ipsum dolor sit amet};
\node [test, right=of f] (g) {gLorem ipsum dolor};
\node [test, below=of f] (h) {hLorem ipsum dolo};
\node [action, below=of h] (i) {iLorem ipsum dolor sit amet, consectetur adipiscing elit.};
\node [action, right=of i, fill=gray] (j) {jLorem ipsum dolor sit amet, consectetur adipiscing elit.};
\node [test, below=of i] (l) {lLorem ipsum dolor};
\node [test, below=of j, fill=gray] (m) {mLorem ipsum dolor};

\draw [red] (g) -- +(0,-10);
\draw [blue] (i) -- +(10,0);
\end{tikzpicture}

\end{document}


I've read some promising things about chains but think it might be over kill for my use.

-

There are two easy approaches to this. If you really just want to place one node "at the intersection of the red and blue lines", you can easily use the perpendicular coordinate system (pgfmanual 2.10 page 130), which is designed for exactly this use. This is shown in the first tikzpicture.

However, as you also requested "everything to be in rows and columns (whose [size] is determined by the largest member)", there is a far better and far more sensible way to achieve the desired effect. Simply use the TikZ \matrix command, which is equivalent to \node[matrix] (pgfmanual 2.10 page 201 and 375). With matrices, you can easily align things in rows and columns without having to worry about things like column types (was with tabular).

Here's an example image of the two techniques applied, followed by the slightly-more-minimal example that produced the image.

\documentclass{article}

\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node[draw] at (0,0) (left node) {Left Node};
\node[draw] at (3,2) (top node) {Top Node};

\node[draw] at (left node -| top node) {Node at intersection};
%\node[draw,circle] at (top node |- left node) {Another node at the same position};

\draw [red] (top node) -- +(0,-3);
\draw [blue] (left node) -- +(6,0);
\end{tikzpicture}

\vspace{1cm}

\begin{tikzpicture}
\matrix[column sep=1cm, row sep=1cm] (m) {
& \node[draw] (top node) {Top Node};\\
\node[draw] (left node) {Left Node}; & \node[draw] {Intersection Node};\\
};
\draw [red] (top node) -- +(0,-3);
\draw [blue] (left node) -- +(6,0);
\end{tikzpicture}

\end{document}

-
You can further use the matrix of nodes key to avoid explicitly typing \node... for each cell. The options the nodes can be given through nodes={draw} key. Also they are directly named as (m-row no-col no) hence you can skip the names. – percusse Sep 5 '12 at 22:30
@percusse: Yes, but doesn't that make adding options to individual cell-nodes more difficult? In the OP's MWE it looks like he'll have very diverse styles for each node, which is why I used explicit \nodes with explicit styles. You're probably right though that I should at least mention that in my answer. – Fritz Sep 5 '12 at 22:45
You are right. Maybe I was carried away a little there but you can overwrite the individual options via &|[draw,blue]| node text per entry which is slightly less work. – percusse Sep 5 '12 at 22:50

You can use the let syntax:

\documentclass{article}

\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, draw,
text centered,
minimum height=3em
]
\tikzstyle{test}    = [ diamond,
draw,
shape aspect=2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action}  = [ rectangle, draw,
text width=8em,
inner sep = 5pt,
minimum height=5em
]

\begin{tikzpicture}[node distance = 1.25em, align = flush center, font = \small]
% Place nodes
\node [test] (f) {fLorem ipsum dolor sit amet};
\node [test, right=of f] (g) {gLorem ipsum dolor};
\node [test, below=of f] (h) {hLorem ipsum dolo};
\node [action, below=of h] (i) {iLorem ipsum dolor sit amet, consectetur adipiscing elit.};
\path let \p1=(g), \p2=(i) in node[action, fill=gray] (j) at (\x1,\y2)   {jLorem ipsum dolor sit amet, consectetur adipiscing elit.};
\node [test, below=of i] (l) {lLorem ipsum dolor};
\node [test, below=of j, fill=gray] (m) {mLorem ipsum dolor};

\draw [red] (g) -- +(0,-10);
\draw [blue] (i) -- +(10,0);
\end{tikzpicture}

\end{document}


-