2

I cannot understand why, in the following example, the first coordinates of the rectangle is correctly shifted and not the second one.

\begin{tikzpicture}
\draw (0,0)+(1,2) rectangle (4,4)+(-1,-2);
\end{tikzpicture}

I see in other posts that I can use 'calc' library, which is working fine for me.

Thanks

  • Does this produce your desired result? \draw (0,0)+(1,2) rectangle {(4,4)+(-1,-2)}; – Konne Sep 9 '15 at 11:21
  • I haven't seen that it also produces an error... – Konne Sep 9 '15 at 11:30
  • Please provide absolute coordinate where the rectangle you like to have. Between (1,2) and (3,2), i.e. actually it is line, not square? – Zarko Sep 9 '15 at 11:31
  • You are right Zarko, but my problem is that I saw a rectangle and not a line, but now I understand with the answer of @Heiko – FrdVnW Sep 10 '15 at 8:56
2

After

\draw (0, 0) + (1, 2)

the starting point of the rectangle is (1, 2) as expected. Then

rectangle (4, 4)

draws the rectangle with end point (4, 4). The remaining stuff

+(-1, -2);

moves to the point (3, 2), but the movement is not visible.

A point can be given options in square brackets, where a shift can be specified:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw (0, 0) +(1, 2) rectangle ([shift={(-1, -2)}] 4, 4);
  \fill[radius=2pt, red] (0, 0) circle[] (4, 4) circle[] ;
\end{tikzpicture}
\end{document}

Result

The rectangle is now a line:

\draw (1, 2) rectangle (3, 2);
  • thanks heiko, I now understand better. It solved my problem – FrdVnW Sep 10 '15 at 8:55

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.