3

As the title describes, I want only the biggest rectangle to have rounded corners.

enter image description here

This is my code now

\begin{tikzpicture}[cell/.style={rectangle,draw=black,thin, minimum size=0.4cm}]
    \begin{scope}
        \node[cell,fill=red!20] at (0,0) {};
        \node[cell,fill=red!20] at (0.8,0) {};
        \node[cell,fill=red!20] at (0.4,0.4) {};
        \node[cell,fill=red!20] at (0,0.8) {};
        \node[cell,fill=red!20] at (0.8,0.8) {};
    \node[cell,fill=blue!30] at (0.4,0) {};
    \node[cell,fill=blue!30] at (0,0.4) {};
    \node[cell,fill=blue!30] at (0.8,0.4) {};
    \node[cell,fill=blue!30] at (0.4,0.8) {};

\end{scope} \end{tikzpicture}

I also wonder if there is a easier way to fill the grid with customized colors.

1 Answers1

4

A simple solution without nodes, like said in my comment above:

\documentclass[tikz,border=3.141592mm]{standalone}
\usetikzlibrary{calc}

\begin{document} \begin{tikzpicture}[line width=1pt]

    \coordinate (A) at (0,0);
    \def\l{1} % length of one third of the grid

    \draw[rounded corners=3pt,fill=red!20] (A) rectangle++ (3*\l,3*\l);
    \foreach \x/\y in {1/0,0/1,1/2,2/1}
        \draw[fill=blue!20] ($(A)+(\x,\y)$) rectangle++ (\l,\l);

\end{tikzpicture}

\end{document}

grid with rounded corners

SebGlav
  • 19,186