Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Any idea why yshift doesn't work in the following TikZ example?

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (2.5,0);
  \draw (A) -- (B);
  \draw[yshift=2cm] (A) -- (B);
\end{tikzpicture}

\end{document}
share|improve this question
    
possible duplicate of Shifting a line joining nodes in TikZ –  Marco Daniel May 24 '13 at 10:16

2 Answers 2

up vote 9 down vote accepted

It would work with coordinates or if you place the yshift inside the parentheses next to the name A and B:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (2.5,0);
  \draw (A) -- (B);
  \draw ([yshift=2cm]A) -- ([yshift=2cm]B);
\end{tikzpicture}

\end{document}

Output:

alt text

share|improve this answer
    
Thanks but it looks odd the way yshift is specified. Any idea why? –  Leo Liu Aug 11 '10 at 13:20
2  
Coordinate transformations do not apply to a node. Its anchor remains the same. See section 15.11 of the pgf manual. –  Stefan Kottwitz Aug 11 '10 at 13:38
2  
I didn't know that one can apply transformations this way to coordinates (I would have used ($(A) - (0,2cm)$)) and the calc library. –  Caramdir Aug 11 '10 at 13:40
    
Before the calc library ([yshift=2cm]A) was the only method, now we have the choice. –  Alain Matthes Mar 8 '12 at 22:57

yshift (and similar commands) are applied to all coordinates in the path, not to the path as a whole. They are also not applied to anchors: according to the TikZ manual (section 15.11. in the 2.0 version):

Once the node x has been defined, you can use (x. anchor ) wherever you would normally use a normal coordinate. This will yield the position at which the given anchor is in the picture. Note that transformations do not apply to this coordinate, that is, (x.north) will be the northern anchor of x even if you have said scale=3 or xshift=4cm. This is usually what you would expect.

share|improve this answer

Your Answer

 
discard

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.