Below is a self-contained example showing how to generate a 7×7 staggered grid of small filled circles with alternating row colors. The code uses TikZ “layout” features—namely, scoping withshiftstyles—to position each row. All parameters (number of rows/columns, circle radius, distances, colors) are collected in easily modifiable\defcommands.
────────────────────────────────────────────────────────────────────
latexCopy code\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
% These specify how many "TikZ units" one step in x or y corresponds to
x=1cm,
y=1cm,
% Define a style "row" that shifts down by row index
row/.style={
shift={(0,-#1*\rowDistance)},
% We can also add default node/circle styles in here if desired
}
]
% -----------------------------
% User-adjustable parameters
% -----------------------------
\def\numRows{7}
\def\numCols{7}
\def\circleRadius{0.1} % Circle radius
\def\rowDistance{0.5} % Vertical distance between rows
\def\colDistance{0.5} % Horizontal distance between circle centers
\def\colorA{red}
\def\colorB{blue}
% -----------------------------
% Loop over rows
\foreach \rowIndex in {0,...,\numexpr\numRows-1} {
%
% Determine if we need a half shift in x-direction
% for every other row
\pgfmathtruncatemacro{\offsetSwitch}{mod(\rowIndex,2)}
\pgfmathsetmacro{\xoffset}{0.5 * \colDistance * \offsetSwitch}
%
% Pick row color (alternates each row)
\ifnum\offsetSwitch=0
\def\rowColor{\colorA}
\else
\def\rowColor{\colorB}
\fi
%
% Start a local scope for this row, shifted vertically
\begin{scope}[row=\rowIndex]
%
% Loop over columns in this row
\foreach \colIndex in {0,...,\numexpr\numCols-1} {
%
% Draw filled circle
\fill[\rowColor]
(\xoffset + \colIndex * \colDistance, 0)
circle(\circleRadius);
}
\end{scope}
}
\end{tikzpicture}
\end{document}
How it works
Parameters:\numRows/\numColsset grid size (at least 7×7).\circleRadiussets how large each dot is.\rowDistanceand\colDistancecontrol vertical/horizontal spacing.\colorAand\colorBset alternating row colors.
\numRows/\numColsset grid size (at least 7×7).
\circleRadiussets how large each dot is.
\rowDistanceand\colDistancecontrol vertical/horizontal spacing.
\colorAand\colorBset alternating row colors.
Staggered Rows:For odd-numbered rows, we compute an extra horizontal offset\xoffset = 0.5 * \colDistance.Even-numbered rows get zero offset.
For odd-numbered rows, we compute an extra horizontal offset\xoffset = 0.5 * \colDistance.
Even-numbered rows get zero offset.
Alternating Colors:A simplemod(\rowIndex,2)check switches between\colorAand\colorB.
A simplemod(\rowIndex,2)check switches between\colorAand\colorB.
Layout with Scopes:Each row is enclosed in a\begin{scope}[row=\rowIndex] ... \end{scope},Therow/.styleshifts each scope downward by\rowIndex * \rowDistance, neatly stacking rows.
Each row is enclosed in a\begin{scope}[row=\rowIndex] ... \end{scope},
Therow/.styleshifts each scope downward by\rowIndex * \rowDistance, neatly stacking rows.
Parameters:
\numRows/\numColsset grid size (at least 7×7).
\circleRadiussets how large each dot is.
\rowDistanceand\colDistancecontrol vertical/horizontal spacing.
\colorAand\colorBset alternating row colors.
\numRows/\numColsset grid size (at least 7×7).
\circleRadiussets how large each dot is.
\rowDistanceand\colDistancecontrol vertical/horizontal spacing.
\colorAand\colorBset alternating row colors.
Staggered Rows:
For odd-numbered rows, we compute an extra horizontal offset\xoffset = 0.5 * \colDistance.
Even-numbered rows get zero offset.
For odd-numbered rows, we compute an extra horizontal offset\xoffset = 0.5 * \colDistance.
Even-numbered rows get zero offset.
Alternating Colors:
A simplemod(\rowIndex,2)check switches between\colorAand\colorB.
A simplemod(\rowIndex,2)check switches between\colorAand\colorB.
Layout with Scopes:
Each row is enclosed in a\begin{scope}[row=\rowIndex] ... \end{scope},
Therow/.styleshifts each scope downward by\rowIndex * \rowDistance, neatly stacking rows.
Each row is enclosed in a\begin{scope}[row=\rowIndex] ... \end{scope},
Therow/.styleshifts each scope downward by\rowIndex * \rowDistance, neatly stacking rows.
Compile withpdflatex filename.texto produce a standalone PDF of your staggered dot grid. Adjust parameters to suit your needs.