Take the 2-minute tour ×
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.

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

1 Answer 1

up vote 3 down vote accepted

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

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \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)};
        }%
    }%
\end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

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.