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

3 Answers 3

up vote 10 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

In such a simple case you can use transform canvas:

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

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

\end{document}

Output:

Output

In more complex scenarios make sure to read the warnings in the PGF manual in section 25.4 Canvas Transformations:

Canvas transformations should be used with great care. In most circumstances you do not want line widths to change in a picture as this creates visual inconsistency. Just as important, when you use canvas transformations pgf loses track of positions of nodes and of picture sizes since it does not take the effect of canvas transformations into account when it computes coordinates of nodes.

share|improve this answer
    
Welcome to TeX.SX! –  Adam Liter Mar 2 at 17:01
    
Don't put some text around that ;) –  percusse Mar 2 at 17:01

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.