[Tex/LaTex] TikZ, center node between 4 nodes

tikz-pgf

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.

Best Answer

You can perhaps use barycentric cs:

output of code

\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}