Tikz 节点的 for 循环

Tikz 节点的 for 循环

我如何构造一个 for 循环以便得到

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

在每个路口?

答案1

使用\foreach循环,步长为0.5

在此处输入图片描述

代码:

\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}

相关内容