# TikZ grid lines

I have the following code:

\draw[step=1.0,black,thin] (0.5,0.5) grid (5.5,4.5);


which I would like to have generate grid lines in the Y direction at y = {0.5, 1.5, 2.5, 3.5, 4.5} and grid lines in the X direction at x = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5}.

However, I get grid lines at y = {1.0, 2.0, 3.0, 4.0} and x = {1.0, 2.0, 3.0, 4.0, 5.0} with half cells around the edges of the grid. So instead of having a closed uniform grid, I get one with open edges and two half cells at the borders.

Does anybody know why it doesn't honor the starting point and stride?

-

The points specify where the grid lines begin and end. The brown grid lines below are the ones you want, but note that that the blue lines which were specified with (0.5,0.5) grid (5.5,4.5) do indeed begin at x=0.5, and y=0.5 and end at x=5.5 and y=4.5.

\documentclass{article}
\usepackage{tikz}

\newcommand*{\xMin}{0}%
\newcommand*{\xMax}{6}%
\newcommand*{\yMin}{0}%
\newcommand*{\yMax}{6}%
\begin{document}
\begin{tikzpicture}
\foreach \i in {\xMin,...,\xMax} {
\draw [very thin,gray] (\i,\yMin) -- (\i,\yMax)  node [below] at (\i,\yMin) {$\i$};
}
\foreach \i in {\yMin,...,\yMax} {
\draw [very thin,gray] (\xMin,\i) -- (\xMax,\i) node [left] at (\xMin,\i) {$\i$};
}

\draw [step=1.0,blue, very thick] (0.5,0.5) grid (5.5,4.5);
\draw [very thick, brown, step=1.0cm,xshift=-0.5cm, yshift=-0.5cm] (0.5,0.5) grid +(5.5,4.5);
\end{tikzpicture}
\end{document}

-
You can use the xshift and yshift options:
\draw[step=1.0,black,thin,xshift=0.5cm,yshift=0.5cm] (0.5,0.5) grid (5.5,4.5);