1

I have a problem with horizontal grid lines in a graph (I am trying to overlay a 1cm x 1cm grid to my pages, and stumbled upon this in the process):

\documentclass{standalone}
\usepackage{tikz}
\begin{document}   
\tikz[]{%
    \draw [help lines,red,ystep=1cm,xstep=1cm] (0,0) node{A} grid +(3cm, -3cm) node{B};
        }   
\tikz[]{%
    \draw [help lines,blue,ystep=1cm,xstep=1cm] (0,0) node{A} grid +(3cm, 3cm) node{B};
        }  
\tikz[]{%
    \draw [help lines,green,ystep=-1cm,xstep=1cm] (0,0) node{A} grid +(3cm, -3cm) node{B};
        }
\end{document}

with this result:

three strange grids

Notice that the green grid has a negative ystep as suggested in Grid missing horizontal lines, but still I have no lines.

So I decided that I probably do not understand how grids are generated; can someone shed some light here?

3
  • Do you really get this image from your MWE? I am getting errors and another output. Please check!
    – LaRiFaRi
    Commented Apr 10, 2015 at 10:38
  • @LaRiFaRi re-checked by cutting and pasting in a new file. I have TeXlive 2013 on an Ubuntu 14.04.2 desktop. No errors. Puzzled.
    – Rmano
    Commented Apr 10, 2015 at 10:43
  • @Rmano: You might want to upgrade your TikZ package to 3.0. On Overleaf, the third image gives an error, but the first two yield the same (correct) result: overleaf.com/2526302tzgdwx#/6615464
    – Jake
    Commented Apr 10, 2015 at 10:51

1 Answer 1

3

Please update your TikZ version. You should not use negative steps if your vectors are not defined in negative directions. Just do like the following in order to span the grid:

% arara: pdflatex

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
    \begin{scope} % south west to north east
        \draw [help lines,red,ystep=1cm,xstep=1cm] (0,0) node{A} grid +(3,3) node{B};
    \end{scope}
    \begin{scope} % north west to south east
        \draw [help lines,blue,ystep=1cm,xstep=1cm] (4,3) node{A} grid +(3,-3) node{B};
    \end{scope}
    \begin{scope} % north east to south west
        \draw [help lines,green,ystep=1cm,xstep=1cm] (11,3) node{A} grid +(-3,-3) node{B};
    \end{scope}
    \begin{scope} % south east to north west
        \draw [help lines,ystep=1cm,xstep=1cm] (15,0) node{A} grid +(-3,+3) node{B};
    \end{scope}
\end{tikzpicture}   
\end{document}

enter image description here

1
  • Althoug I think that this is the correct answer --- with my current tikz using ` \draw [help lines,green,ystep=1cm,xstep=1cm] (0, -3cm) grid (3cm, 0) (0, 0) node {A} (3cm, -3cm) node {B};` --- IOW, specifying always `(bottom left corner) grid (upper right corner). Thanks.
    – Rmano
    Commented Apr 10, 2015 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .