2

I use this to reverse the coordinate system in latex, e.g. direct y axis down. The example of replacing path in this CS

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{pgffor}

\begin{document}
\begin{tikzpicture}[y=-1cm]
  \foreach \y in {0,...,3}
  {
    \draw[red] (0,\y) -- (5,\y) node[right,red]{\y} ;
    \draw [decorate,decoration={brace,mirror,amplitude=5mm},yshift=\y{}cm]
      (0,0) -- (5,0) node [black,midway,yshift=-7mm,below]{\y};
  }
\end{tikzpicture}
\end{document}

gives me this result Result

As you can see, positive y coordinate runs downward, but positive shift runs upward. Why shift works in another direction than drawing? Is it a bug or shift mechanism have different system than usual CS?

  • It is not a bug; I guess it is documented somewhere. The shifts are not affected by coordinate transformations. – gernot Mar 26 '17 at 09:44

1 Answers1

3

Tikz coordinate system works with two (unit) vectors, one for x and one for y. With the option [y=-1cm] you set the y-vector to (0,-1cm). Then in your code e.g. (0,3) represents a point in this coordinate system, in this case (0cm,-3cm). But when you specify absolute coordinates like (0cm,3cm) this is already a point and the unit vectors will not scale it. In your code, if you change the line to

\draw[red] (0,\y cm) -- (5,\y cm) node[right,red]{\y} ;

you will see the difference. Now, the problem is that yshift cannot be set with the relative coordinate, but has to go with a unit. If not given it assumes pt.

There is an alternative to set the negative vector. Instead use yscale to scale the whole picture. (of course you can restrict it to a scope).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{pgffor}

\begin{document}
\begin{tikzpicture}[yscale=-1]%[y=-1cm]
  \foreach \y in {0,...,3}
  {
    \draw[red] (0,\y) -- (5,\y) node[right,red]{\y} ;
    \draw [decorate,decoration={brace,mirror,amplitude=5mm},yshift=\y cm]
      (0,0) -- (5,0) node [black,midway,yshift=-7mm,below]{\y};
  }
\end{tikzpicture}
\end{document}

enter image description here

StefanH
  • 13,823