6

Is there a simple way to add coordinate (left and bottom) to the grid in tikz?

Per
  • 241
  • 2
    The question is not very clear at the moment. Could you explain in a little more detail what you're trying to achieve, preferably with a minimal example document? – Jake Apr 26 '13 at 16:05
  • Are you looking for something like this: grid in pgfplots? – Alexander Apr 26 '13 at 16:22
  • I think the OP wants to add coordinates to specified nodes on a grid without having to manually enter them. @Per Could you please confirm? – kan Apr 26 '13 at 16:25
  • @kan: When I want to draw a complex diagram I superimpose two large grids covering the entire page, one with step=1 and one with step=0.2. Then when I want to place an object (e.g., rectangle) I have to "count" on the grid to get the desired coordinates. What I am looking for is labeling the grid at the bottom and on the left so that finding coordinates of points on the grid becomes easier – Per Apr 26 '13 at 16:46
  • 2
    You could be interested in Andrew's answer to http://tex.stackexchange.com/q/39553/3954, which defines a grid with coordinates style which allows you simply to say \draw (-2,-2) to[grid with coordinates] (7,4); – Gonzalo Medina Apr 26 '13 at 17:08
  • @Gonzalo Medina: Thanks. That is exactly what I wanted, but I thought there should be a simpler option in grid to do this! Apparently I was wrong. – Per Apr 26 '13 at 20:33

1 Answers1

7

I think this is what is wanted:

\documentclass[tikz]{standalone}
\begin{document}
%
\begin{tikzpicture}
% Draw the grid
\tikzset{help lines/.style={color=blue!50}}
\draw[thick,step=1cm,help lines] (0,0) grid (9,9);
\draw[ultra thin,step=.5cm,help lines] (0,0) grid (9,9);
% Draw axes
\draw[ultra thick,-latex] (0,0) -- (10,0);
\draw[ultra thick,-latex] (0,0) -- (0,10);
% the co-ordinates -- major
\foreach \x in {0,1,...,9} {     % for x-axis
\draw [thick] (\x,0) -- (\x,-0.2);
}
\foreach \y in {0,1,...,9} {   %% for y-axis
\draw [thick] (0,\y) -- (-0.2,\y);
}
% the numbers
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x,-0.3) {\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (-0.3,\y) {\y}; }
% the co-ordinates -- minor
\foreach \x in {.5,1.5,...,8.5} {
\draw [thin] (\x,0) -- (\x,-0.1);
}
\foreach \y in {.5,1.5,...,8.5} {
\draw [thin] (0,\y) -- (-0.1,\y);
}
\end{tikzpicture}
%
\end{document}

enter image description here

  • 3
    Yes this is pretty much what I want to get (without the two axis). But is this really the simplest way to do this? I thought that grid must have some options to get this result. – Per Apr 26 '13 at 16:51