![如何在 tikz 中绘制圆角网格](https://linux22.com/image/430569/%E5%A6%82%E4%BD%95%E5%9C%A8%20tikz%20%E4%B8%AD%E7%BB%98%E5%88%B6%E5%9C%86%E8%A7%92%E7%BD%91%E6%A0%BC.png)
正如标题所述,我想要只有最大的矩形圆角。
这是我现在的代码
\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}
我还想知道是否有更简单的方法来用自定义颜色填充网格。
答案1
一个没有节点的简单解决方案,就像我上面的评论中所说的那样:
\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}