I used the following code to draw a grid, and to fill certain cells with certain fills or shapes.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\begin{document}
\tikzset{
pics/square/.default={1.5},
pics/square/.style = {
code = {
\draw[pic actions] (0,0) rectangle (#1,#1);
}}}
\begin{center}
\begin{tikzpicture}
\foreach \x in {1,2,...,5} {
\foreach \y in {1,2,...,5} {
\pic[fill=white] at (\x,\y) {square};
}
}
\node[regular polygon,regular polygon sides=4,draw=black,thick, fill=blue,minimum size=.8cm] at (5.5,4.5) {};
\pic[draw=black,thick,fill=red] at (2,2) {square};
\end{tikzpicture}
\end{center}
\end{document}
When I used the code
pics/square/.default={1},
I got a square grid.
But when I used the code
pics/square/.default={1.5},
to get a larger grid size, the grid became rectangles not squares.
How can this be fixed by increasing the default grid size, without increasing the scale of the \tikzpicture.



foreachloops and you use{1,2,...}inside them. This is the issue. You have to modify your increment into theforeachloops, depending on your default square siez. – SebGlav Dec 29 '21 at 08:19