1

In TikZ, I have defined two coordinates by

\coordinate (A) (1, 2);
\coordinate (B) (5, 3);

Is there a simple way to define the middle of A and B? I'm looking for a command such as

\coordinate (M) (A)!0.5!(B);

Thanks

Colas
  • 6,772
  • 4
  • 46
  • 96
  • 6
    Probably \coordinate (M) at ($(A)!0.5!(B)$); with the calc library loaded – BambOo Nov 11 '20 at 18:19
  • Or \path (1,2) coordinate (A) -- coordinate (M) (5,3) coordinate (B);. BTW, your syntax \coordinate (A) (1, 2); is wrong, it should be \coordinate (A) at (1, 2); or \path (1,2) coordinate (A);. –  Nov 11 '20 at 18:33
  • As mentioned above, https://tex.stackexchange.com/questions/66914/using-tikz-coordinates-in-expressions https://tex.stackexchange.com/questions/71478/how-to-center-one-node-exactly-between-two-others-with-tikz – Torbjørn T. Nov 11 '20 at 22:01
  • @BambOo Can you write an answer? Thanks – Colas Nov 12 '20 at 10:22
  • As Torbjorn T. said, this is already answered in order posts. – BambOo Nov 12 '20 at 10:47
  • Yes it's true, but I would say that adding the answer here can be positive for the TeX community. – Colas Nov 12 '20 at 12:47

1 Answers1

3

As pointed out in the comments, this answer is mostly a reminder of Claudio Fiandrino's or Jake's answers.

To compute coordinates based on two other coordinates, TikZ proposes the calc library depicted in details in section §13.5 of the pgfmanual (accessible on CTAN or with texdoc pgfmanual.pdf if installed).

More specifically, the syntax required by the calc library to compute coordinates from others takes the form ($<coordinate 1>!<factor / dimension / coordinate>!<angle>:<coordinate 2>$) and fall under the scope of so-called Partway / Distance / Projection Modifiers.

Note the ($...$) enclosing which is required !

In your case, you are interested in the partway modification, because you try to compute the coordinates midway (hence at a 0.5-0.5 normalized distance) between two other ones.

In the end the syntax should therefore be \coordinate (M) at ($(A)!0.5!(B)$); where

  • <coordinate1> = (A)
  • <factor> = 0.5 for the midway point
  • <angle> = {} so assumed null
  • <coordinate2> = (B)
BambOo
  • 8,801
  • 2
  • 20
  • 47