TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following code:

  \coordinate (V11) at (0,0);
  \coordinate (V44) at (4,4);
  \draw[black] (V11) rectangle (V\MA\MA);

This works. However changing the \draw command to:

   \draw[black] (V11) rectangle (V\MB\MB);

produces the following error:

! Package pgf Error: No shape named V4 is known .

Why is \newcommand working here, when \pgfmathsetmacro fails?

share|improve this question
Related Question: What is the preferred way of defining a TikZ constant?. – Peter Grill Jan 21 '13 at 23:28
up vote 16 down vote accepted

The reason is that \pgfmathsetmacro{\MB}{4} (there is no ; required) sets \MB to the arithmetic result of 4.0 not 4. Therefore you get V4.04.0 as node expression. Everything after a dot is taken as node anchor, i.e. TikZ looks for a node V4 with the anchor 04.0, which leads to the error you get. (Numeric anchors are also taken as angle (in degrees), so V\MB would be node V4 with the angle node at 0 degrees.)

To fix this use \pgfmathtruncatemacro{\MB}{4} which will give you 4.

See also the related questions How to draw lines between nodes that point at the node center, but stop at the nodes edge and Referring to tikz matrix coordinates using pgf mathematics operations, which where caused from the same behaviour of \pgfmathsetmacro.

share|improve this answer
Thank you :-) This was exactly what I was looking for. Great answer! – Håkon Hægland Jan 22 '13 at 8:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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