TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 12 down vote accepted

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.        

enter image description here


    \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);
share|improve this answer

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);
share|improve this answer
Is it possible to "easily" add the labels? – anderstood Aug 30 '15 at 23:09
Probably not, but perhaps you can put it in a separate command, so that you can use e.g. \gridlabel{xmin}{ymin}{xmax}{ymax}? – Tom Bombadil Aug 31 '15 at 7:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.