6

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.

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

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}
  • Can you explain the code cs:a=1,b=1,c=1,d=1? – minhthien_2016 Nov 23 '17 at 15:57
  • 3
    @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.