TikZ, center node between 4 nodes

With tikz library calc, it is possible to center a node between two points:

\node (node3) at ($(node1)!0.5!(node2)$) {centered};


Whatever is the direction of the line passing through node1 and node2, this makes node3 horizontally centered along this direction.

Is is possible to center instead a node between 4 nodes, when they form a regular shape such as a square, or rectangle, or rhombus? So that the node is both horizontally and vertically centered.

• Keep adding : ($($(node1)!0.5!(node2)$)!0.5!($(node3)!0.5!(node4)$)$) – percusse Nov 23 '17 at 15:39

You can perhaps use barycentric cs:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node (a) at (-2,2) {1};
\node (b) at (2,2) {2};
\node (c) at (-2,-2) {3};
\node (d) at (2,-2) {4};

\node (e) at (barycentric cs:a=1,b=1,c=1,d=1) {5};
\end{tikzpicture}
\end{document}

• Can you explain the code cs:a=1,b=1,c=1,d=1? – minhthien_2016 Nov 23 '17 at 15:57
• @toandhsp Section 13.2.2 Barycentric systems in the manual. Essentially, the coordinate is defined by a linear combination of the vectors a, b, c and d (these are the named coordinates), when all the vectors are weighted equally, you get the center point. – Torbjørn T. Nov 23 '17 at 16:01