如何在另一个方形框内添加一个方形框?

如何在另一个方形框内添加一个方形框?

是否可以在 LaTex 中创建下面显示的图片?我对这个软件还不太熟悉,任何帮助都将不胜感激。我知道如何开始正方形的代码,但我不知道如何在其中添加正方形和点。

谢谢!

在此处输入图片描述

答案1

极简解决方案。无需额外软件包。

\documentclass{article}

\begin{document}

\fbox{%
    \begin{tabular}{ccc}
        \fbox{$\bullet$} & \fbox{$\bullet$} & \fbox{$\circ$} \\
        \fbox{$\circ$} & \fbox{$\bullet$} & \fbox{$\circ$} \\
        \fbox{$\circ$} & \fbox{$\circ$} & \fbox{$\bullet$} \\
    \end{tabular}%
}

\end{document}

在此处输入图片描述

答案2

另一种解决方案,不像 Henri Menke 解决方案那么简单,但也不太冗长

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (a) [draw, matrix of math nodes, nodes={draw, anchor=center},
row sep=1mm, column sep=1mm]{%
\bullet & \bullet & \circ\\
\circ & \bullet & \circ\\
\circ & \circ & \bullet\\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

这应该很有用

\begin{center}
%\fbox{
\begin{tikzpicture}
    \begin{scope}[
        box1/.style={draw=black, thick, rectangle,rounded corners, minimum height=0.75cm, minimum width=0.75cm}]
\draw[black,dashed,fill=red!30] (-.5,-3.2) rectangle (3.2,.5);
\node[box1, fill=green!30] (c1) {};
\node[box1, fill=green!30, right=.125cm of c1] (c2) {};
\node[box1, fill=green!30, right=.125cm of c2] (c3) {};
\node[box1, fill=green!30, right=.125cm of c3] (c4) {};
\node[box1, fill=green!30, below=.125cm of c4] (c5) {};
\node[box1, fill=green!30, left=.125cm of c5] (c6) {};
\node[box1, fill=green!30, left=.125cm of c6] (c7) {};
\node[box1, fill=green!30, left=.125cm of c7] (c8) {};
\node[box1, fill=green!30, below=.125cm of c8] (c9) {};
\node[box1, fill=green!30, right=.125cm of c9] (c10) {};
\node[box1, fill=green!30, right=.125cm of c10] (c11) {};
\node[box1, fill=green!30, right=.125cm of c11] (c12) {};
\node[box1, fill=green!30, below=.125cm of c12] (c13) {};
\node[box1, fill=green!30, left=.125cm of c13] (c14) {};
\node[box1, fill=green!30, left=.125cm of c14] (c15) {};
\node[box1, fill=green!30, left=.125cm of c15] (c15) {};
        \end{scope}
\end{tikzpicture}
%}
\end{center}

在此处输入图片描述

相关内容