0

The following example should show a square and a smaller copy of it inside, the commands xscale and yscale work when I write the coordinates manually on both paths, but when I reference the coordinates defined previously, it doesn't.

\documentclass{minimal}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (-1,1);
\coordinate (B) at (1,1);
\coordinate (C) at (1,-1);
\coordinate (D) at (-1,-1);
\draw (A) to (B) to (C) to (D) to cycle;
\draw[xscale=0.5,yscale=0.5] (A) to (B) to (C) to (D) to cycle;
\end{tikzpicture}
\end{document}

This image shows the expected versus the obtained figure.

enter image description here

EDIT: Apparently I forgot to explicit my question, how to properly get this done? Apply scalings, or any transformation in general, to previously defined coordinates?

F.Webber
  • 235
  • 2
    You can check this question. – Kpym Apr 28 '18 at 17:58
  • Thanks, that question seems to provide appropriate answers. – F.Webber Apr 28 '18 at 18:05
  • 1
    Of course, you can scale the (named) coordinates with the calc library (\usetikzlibrary{calc}) : \draw ($0.5*(A)$) to ($0.5*(B)$) to ($0.5*(C)$) to ($0.5*(D)$) to cycle; or shorter \draw ($0.5*(A)$) rectangle ($0.5*(C)$);. –  Apr 28 '18 at 18:16
  • 1
    @marmot you don't need calc for this ([scale=.5]A) works. – Kpym Apr 28 '18 at 19:25
  • @Kpym Cool. Didn't know that! Good to know. I think you should answer that question, then. And merci! –  Apr 28 '18 at 19:29
  • @Kpym Arguably even simpler: \draw[transform canvas={xscale=0.5,yscale=0.5}] (A) to (B) to (C) to (D) to cycle; This should also work here. –  Apr 28 '18 at 19:36
  • @marmot simpler, may be, but not equivalent, as you know. If you really want a global style, check this Mark Wibrow's answer. – Kpym Apr 28 '18 at 19:39
  • @Kpym I know, but depending on the needs transform canvas may be OK or even better than the other solution. (I upvoted both your and Mark's answer... ) –  Apr 28 '18 at 19:41

0 Answers0