TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

How do I construct a for loop so that I get

\draw [step=0.5cm, gray!80] (0,0) grid (4,4);
\draw [orange] plot [only marks, mark size=2.5, mark=*] coordinates {(0,0) (4,4)};

at every intersection?

share|improve this question
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Apr 5 '13 at 21:01
@PeterGrill My mistake. Thanks for letting me know. – AlanH Apr 5 '13 at 21:06
up vote 3 down vote accepted

Use a \foreach loop, with a step size of 0.5:

enter image description here


    \draw [step=0.5cm, gray!80] (0,0) grid (4,4);
    \foreach \x in {0,0.5,...,4} {%
        \foreach \y in {0,0.5,...,4} {%
            \draw [orange] plot [only marks, mark size=2.5, mark=*] 
                coordinates {(\x,\y)};
share|improve this answer

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.