6

I have trouble understanding the tikz inheritance model while using the positioning library.

Consider the following example:

\documentclass[]{scrbook}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[black,node distance=5mm]
  \node[draw] (0) {origin};
  \node[draw,below=of 0,node distance=20mm] {A};
  \node[draw,node distance=20mm,below=of 0] {B};

  \begin{scope}[xshift=30mm]
    \node[draw] {xshifted origin};
    \node[draw,below=of 0,yshift=-30mm] {C};
    \node[draw,yshift=-30mm,below=of 0,xshift=30mm] {D};
  \end{scope}
\end{tikzpicture}

\end{document}

which leads to the following result:

result

And now the questions:

  1. Why does overriding the node distance work in B, but not in A?
  2. Using below seems to override the scope xshift in C, but it seems to be working both, before and after below in D, so this seems to be a different behavior from A / B. Why?

Any ideas are welcome. :)

  • In A, below of 0 comes first and it is executed while in B, it comes when there is already a particular node distance in force. For second, you are using 0 as a reference point and shifts are executed with respect to it. – user11232 Apr 28 '14 at 23:10
7

The keys are set as they are stumbled upon, so if you set a key that is used by the key that comes after it, it will affect. Otherwise, it will be set but the key that uses it would be already set.

In referring to node names, 0 already exists as a fixed position in canvas. Having a different transformation in effect doesn't change its canvas position unless you go low level canvas transformation which simply goes full speed without checking what is what.

Also, by adding a soft transformation to the scope adds that to all paths but transformations only affects explicit coordinates such as (3,2) not to the refering labels. Quick example

\begin{tikzpicture}
\draw[style=help lines] (-1,-1) grid[step=1] (2,2);
  \coordinate (o);
  \begin{scope}[xshift=1cm]
  \draw[red,thick] (o) -- (1,1);
  \end{scope}
\end{tikzpicture}

enter image description here

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.