# positioning a node relative to multiple nodes

I would like to place a node relative to multiple nodes. In this post, the calc library is suggested in one of the answers. In the below picture, the centered node (E) is not placed in the exact center of all nodes.

I can solve this problem by determining the exact position of each node but I would like to take advantage of positioning package to carry it out automatically. Is there a way to position a node relative to multiple nodes automatically? (i.e. I mean like below=of right=of ... etc.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows, decorations.pathmorphing, backgrounds, positioning,fit,petri}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
place/.style={circle,draw=blue!50,fill=blue!20,thick,
inner sep=0pt,minimum size=6mm}
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\node[place] (A)               {A};
\node[place] (B) [right=of A]  {B};
\node[place] (C) [below=of B]  {C};
\node[place] (D) [left=of  C]  {D};
\coordinate (Middle) at ($(A)!0.5!(B)$);
\node[place] (E) [below of=Middle] {E};

\end{tikzpicture}
\end{document}


You can use baricentric cs for such jobs. For details, see the pgfmanual, page 133, section 13.2.2.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows, decorations.pathmorphing, backgrounds, positioning,fit,petri}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
place/.style={circle,draw=blue!50,fill=blue!20,thick,
inner sep=0pt,minimum size=6mm}
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\node[place] (A)               {A};
\node[place] (B) [right=of A]  {B};
\node[place] (C) [below=of B]  {C};
\node[place] (D) [left=of  C]  {D};
\coordinate (Middle) at ($(A)!0.5!(B)$);
\node[place] (E)  at (barycentric cs:A=0.5,B=0.5,C=0.5,D=0.5)  {E};

\end{tikzpicture}
\end{document}


You can adjust those 0.5 to alter the position.

The barycentric coordinate system in Harish's answer provides a fairly general method; in this concrete case, however you can use the calc library (already loaded in your code) simply say

\node[place] (E) at ( $(A)!0.5!(C)$ ) {E};


The complete code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}[
place/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=0pt,minimum size=6mm}
]
\node[place] (A) {A};
\node[place] (B) [right=of A] {B};
\node[place] (C) [below=of B] {C};
\node[place] (D) [left=of  C] {D};
\node[place] (E) at ( $(A)!0.5!(C)$ ) {E};
\end{tikzpicture}

\end{document}


• Or just \path (A) -- node[place] (E) {E} (C); which doesn't use calc library. – Ignasi Sep 3 '15 at 7:22
• @GonzaloMedina, thank you for the answer. Even though this solves the problem but it doesn't address positioning a node relative to multiple nodes. I feel Harish Kumar's answer addresses this issue by considering all the nodes. Upvoted though, Cheers – CroCo Sep 4 '15 at 14:18