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.

Why wont xshift work here?

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \coordinate (Q) at (2.1cm, -1cm);

  \draw[xshift = 0.5cm] (Q) -- +(0, 3cm); % no shift

  \begin{scope}[xshift = 0.5cm]
    \draw (Q) -- +(0, 3cm); % no shift
  \end{scope}
\end{tikzpicture}
\end{document} 

Both the scoped and non-scoped version produce the same image:

enter image description here

As we can see, the line is drawn from Q and not shifted.

share|improve this question
2  
\draw (Q) ++(0.5cm,0) -- +(0,3cm); –  JLDiaz May 27 at 16:06
    
@JLDiaz so xshift wont or can't work in this case? –  dustin May 27 at 16:06
    
Apparently named nodes cannot be shifted. Their names make them somewhat "absolute" –  JLDiaz May 27 at 16:07
    
@JLDiaz do you want to make an answer? I used your comment to solve my problem. –  dustin May 27 at 16:17
    
Ok, I elaborated it a bit –  JLDiaz May 27 at 16:51

3 Answers 3

up vote 7 down vote accepted

As explained in another answer, named nodes are somewhat "absolute" coordinates, and they are not affected by standard transforms (shift, rotate, scale, etc.) They can be transformed via a transform canvas, however, but this is generally discouraged, specially for scale changes, because it affects also to the size and aspect of strokes, fonts, etc.

So, leaving shifts alone, which alternatives do we have?

  1. Use calc to manually add some amount to each coordinate, e.g: ($(Q)+(0.5, 0)$)
  2. Use ++ syntax to set a new "origin" and + syntax to specify coordinates relative to that origin.

Using the second approach for this particular case:

\draw (Q) ++(0.5, 0) -- +(0,3);

which means:

  1. Go to coordinate (Q)
  2. Move (0.5,0) from that coordinate and set this new point as origin for relative coordinates
  3. Draw a line from the last point to the one which is at (0,3) from it.
share|improve this answer

AFAIK named coordinates survive a transformation unchanged unless the canvas is transformed:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \coordinate (Q) at (2.1cm, -1cm);
  \draw (Q) -- +(0, 3cm);

  \draw[transform canvas={xshift = 0.5cm}] (Q) -- +(0, 3cm);

  \begin{scope}[transform canvas={xshift = 1cm}]
    \draw (Q) -- +(0, 3cm);
  \end{scope}
\end{tikzpicture}
\end{document}

Result

share|improve this answer

You can shift named coordinates if you apply shift to each coordinate, not to the whole scope:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \coordinate (Q) at (2.1cm, -1cm);

  \draw[xshift = 0.5cm] (Q) -- +(0, 3cm) node[midway, above,sloped] {no shift};

  \draw[red] ([xshift = 0.5cm]Q) -- +(0, 3cm) node[midway, above,sloped] {shifted}; 

\end{tikzpicture}
\end{document} 

enter image description here

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.