TransWikia.com

Change size of a Checker pattern

TeX - LaTeX Asked by pankaj singh on June 13, 2021

I have made a 5 x 5 square checker pattern using the code below. How can I change it to 4 x 10 rectangular checker pattern?

documentclass[tikz]{standalone}

begin{document}

begin{tikzpicture}
edefsize{4}
    foreach x in {0,...,size} foreach y in {0,...,size} {
        pgfmathsetmacro{colour}{(x==y || x+y==size) ? "none" : "none"}
        draw[fill=colour] (x,y) rectangle ++ (1,1);
    }
end{tikzpicture}

end{document}

2 Answers

So just change the values or am I missing something?

foreach x in {0,...,9} foreach y in {0,...,3}.

enter image description here

Answered by Roland on June 13, 2021

Here is one way.

enter image description here

documentclass[tikz,border=5mm]{standalone}
pagecolor{gray}
begin{document}
begin{tikzpicture}
defn{10} % number of columns 
defm{4}  % number of rows
foreach i in {1,...,n}
foreach j in {1,...,m}
{
pgfmathparse{mod(i+n-j,2) ? "red" : "white"}
fill[pgfmathresult] (i,j) rectangle +(1,1);
}
end{tikzpicture}
end{document}

And yet another way

enter image description here

documentclass[tikz,border=5mm]{standalone}
pagecolor{lightgray}
begin{document}
begin{tikzpicture}
fill[white] (0,0) rectangle (10,4);    
foreach i in {0,2,...,8} foreach j in {0,2}
fill[orange] (i,j) rectangle +(1,1) (i+1,1+j) rectangle +(1,1);
end{tikzpicture}
end{document}

Answered by Black Mild on June 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP