[Tex/LaTex] Help understanding the coordinate system used in tikz

coordinatestikz-pgf

I'm trying to understand how the coordinate system work for drawing pictures with tikz. I'm a little lost…

Here is a MWE that shows of some example code:

\documentstyle{article}

\begin{document}
\usetikzlibrary{shapes}
\usetikzlibrary{backgrounds,fit,shapes}
\usetikzlibrary{positioning}


\begin{tikzpicture}
  \tikzstyle{Y} = [rectangle, fill=orange!30!white]
  \tikzstyle{X} = [rectangle, fill=green!30!white]
  \tikzstyle{Other} = [rectangle, fill=blue!30!white]

\draw [help lines] (0,0) grid (100,10);

  \node [Y, anchor=south west, minimum width=200,minimum height=10] (Response) at (0,0) {};
  \node [below=of Response] {\small Variation in response};

  \node [X, anchor=south west, minimum width=75,minimum height=10] (Explanatory) at (0,0) {};
  \node [above=of Explanatory] {\small Explanatory};

  \node [Other, anchor=south west, minimum width=50,minimum height=10] (Other) at (75,0) {};
  \node [above=of Other] {\small Other};

\end{tikzpicture}

\end{document}

enter image description here

This is what was expecting, and wanting:

  • My first rectangle would start at coordinate (0,0) and end at (200, 10) because the width was set as 200 minimum, and height at 10 minimum, and the south west anchor was (0,0).
  • My second rectangle would start at (0,0), and end at (75, 10) for the same reason.
  • My third rectangle would start at (75, 0), because the rectangle is placed at (75, 0) and anchored "south west" like all others. But it doesn't even appear at all on my picture… it is way, way to the right (off the page). It starts somewhere I wasn't expecting.

That third point is where it breaks down for me. Can someone please explain? I'll try to explain my confusion further.

In the second rectangle, I assumed that the rectangle was starting at (0,0) and ending at (75, 10) because of the width and height I provide. But when I place the third rectangle at to start at (75, 0), it starts somewhere else; why is it somewhere different?

Probably an easy explanation, but I don't see it.

[I am trying to draw a rectangle, and then cut it into sub-rectangles. This is a MWE, so it is more involved than this, with things changing slide-by-slide in beamer. But that's the context.]

Thanks.

P.

Best Answer

By default, tikz uses centimeters (cm) as unit. You are using dimensions of the order of 200 (meaning 200cm) resulting in your image going beyond page and part of the image is not seen. Try setting [x=1mm,y=1mm], specifying all dimensions in mm and changing (unrelated) all tikzstyles (deprecated) to tikzset brings the image within the page.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{backgrounds,fit,shapes}
\usetikzlibrary{positioning}
\tikzset{X/.style = {rectangle, fill=orange!30!white},
         Y/.style = {rectangle, fill=green!30!white},
         Other/.style = {rectangle, fill=blue!30!white}
}

\begin{document}



\begin{tikzpicture}[x=1mm,y=1mm]
\draw [thin,dashed][help lines,step=5mm] (0,0) grid (125,20);
\draw [help lines,step=10mm] (0,0) grid (125,20);

  \node [Y, anchor=south west, minimum width=100mm,minimum height=10mm] (Response) at (0,0) {};
  \node [below=of Response] {\small Variation in response};

  \node [X, anchor=south west, minimum width=75mm,minimum height=5mm] (Explanatory) at (0,0) {};
  \node [above=of Explanatory] {\small Explanatory};

  \node [Other, anchor=south west, minimum width=50mm,minimum height=5mm] (Other) at (75mm,1mm) {};
  \node [above=of Other] {\small Other};

\end{tikzpicture}

\end{document}

enter image description here

The dashed lines are 5mm apart from 0 to 125mm and the solid ones are 10mm apart. Hope this is helpful.