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?

  • 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. Apr 5 '13 at 21:01
  • @PeterGrill My mistake. Thanks for letting me know. Apr 5 '13 at 21:06

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)};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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