我在波多黎各数学奥林匹克竞赛上看到下面这张图,图中是一张展开的地毯。
我无法完成圆柱体的部分,无法在黑色方块上引入符号
\documentclass{exam}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{latexsym} %simbolos do Latex
\usepackage{bbm} %simbolos de conjuntos
\usepackage{pstricks}
\usepackage{pstricks-add, pst-eucl, here}
\usepackage{MnSymbol}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.8, angle=90]
\draw[ultra thick](0,0)--(7,0)--(7,9)--(0,9)--(0,0);
\draw[thick] (1,0)--(1,9);
\draw[thick] (2,0)--(2,9);
\draw[thick] (3,0)--(3,9);
\draw[thick] (4,0)--(4,9);
\draw[thick] (5,0)--(5,9);
\draw[thick] (6,0)--(6,9);
\draw[thick] (7,0)--(7,9);
\draw[thick] (0,1)--(7,1);
\draw[thick] (0,2)--(7,2);
\draw[thick] (0,3)--(7,3);
\draw[thick] (0,4)--(7,4);
\draw[thick] (0,5)--(7,5);
\draw[thick] (0,6)--(7,6);
\draw[thick] (0,7)--(7,7);
\draw[thick] (0,8)--(7,8);
\draw[thick] (0,9)--(7,9);
\draw[thick,<-] (-0.5,0)--(-0.5,4);
\draw[thick,->] (-0.5,4.5)--(-0.5,9);
\draw[thick,<-] (0,-0.5)--(2.6,-0.5);
\draw[thick,->] (3.7,-0.5)--(7,-0.5);
\draw[fill=black] (0,1) rectangle (1,2);
\draw[fill=black] (2,1) rectangle (3,2);
\draw[fill=black] (4,1) rectangle (5,2);
\draw[fill=black] (6,1) rectangle (7,2);
\draw[fill=black] (0,3) rectangle (1,4);
\draw[fill=black] (2,3) rectangle (3,4);
\draw[fill=black] (4,3) rectangle (5,4);
\draw[fill=black] (6,3) rectangle (7,4);
\draw[fill=black] (0,5) rectangle (1,6);
\draw[fill=black] (2,5) rectangle (3,6);
\draw[fill=black] (4,5) rectangle (5,6);
\draw[fill=black] (6,5) rectangle (7,6);
\draw[fill=black] (0,7) rectangle (1,8);
\draw[fill=black] (2,7) rectangle (3,8);
\draw[fill=black] (4,7) rectangle (5,8);
\draw[fill=black] (6,7) rectangle (7,8);
\draw[fill=black] (1,6) rectangle (2,7);
\draw[fill=black] (3,6) rectangle (4,7);
\draw[fill=black] (5,6) rectangle (6,7);
\draw[fill=black] (3,0) rectangle (4,1);
\draw[fill=black] (5,0) rectangle (6,1);
\draw[fill=black] (1,0) rectangle (2,1);
\draw[fill=black] (1,2) rectangle (2,3);
\draw[fill=black] (3,2) rectangle (4,3);
\draw[fill=black] (5,2) rectangle (6,3);
\draw[fill=black] (1,4) rectangle (2,5);
\draw[fill=black] (3,4) rectangle (4,5);
\draw[fill=black] (5,4) rectangle (6,5);
\draw[fill=black] (1,8) rectangle (2,9);
\draw[fill=black] (3,8) rectangle (4,9);
\draw[fill=black] (5,8) rectangle (6,9);
\node at (0.5,0.5) {\LARGE{\textbf{$\ostar$}}};
\node at (0.5,2.5) {\LARGE{\textbf{$\ostar$}}};
\node at (0.5,4.5) {\LARGE{\textbf{$\ostar$}}};
\node at (0.5,6.5) {\LARGE{\textbf{$\ostar$}}};
\node at (0.5,8.5) {\LARGE{\textbf{$\ostar$}}};
\node at (1.5,1.5) {\LARGE{\textbf{$\ostar$}}};
\node at (1.5,3.5) {\LARGE{\textbf{$\ostar$}}};
\node at (1.5,5.5) {\LARGE{\textbf{$\ostar$}}};
\node at (1.5,7.5) {\LARGE{\textbf{$\ostar$}}};
\node at (2.5,0.5) {\LARGE{\textbf{$\ostar$}}};
\node at (2.5,2.5) {\LARGE{\textbf{$\ostar$}}};
\node at (2.5,4.5) {\LARGE{\textbf{$\ostar$}}};
\node at (2.5,6.5) {\LARGE{\textbf{$\ostar$}}};
\node at (2.5,8.5) {\LARGE{\textbf{$\ostar$}}};
\node at (3.5,1.5) {\LARGE{\textbf{$\ostar$}}};
\node at (3.5,3.5) {\LARGE{\textbf{$\ostar$}}};
\node at (3.5,5.5) {\LARGE{\textbf{$\ostar$}}};
\node at (3.5,7.5) {\LARGE{\textbf{$\ostar$}}};
\node at (4.5,0.5) {\LARGE{\textbf{$\ostar$}}};
\node at (4.5,2.5) {\LARGE{\textbf{$\ostar$}}};
\node at (4.5,4.5) {\LARGE{\textbf{$\ostar$}}};
\node at (4.5,6.5) {\LARGE{\textbf{$\ostar$}}};
\node at (4.5,8.5) {\LARGE{\textbf{$\ostar$}}};
\node at (5.5,1.5) {\LARGE{\textbf{$\ostar$}}};
\node at (5.5,3.5) {\LARGE{\textbf{$\ostar$}}};
\node at (5.5,5.5) {\LARGE{\textbf{$\ostar$}}};
\node at (5.5,7.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,0.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,2.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,4.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,6.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,8.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,1.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,3.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,5.5) {\LARGE{\textbf{$\ostar$}}};
\node at (6.5,7.5) {\LARGE{\textbf{$\ostar$}}};
\node at (1.5,8.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (1.5,5.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (3.5,0.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (3.5,2.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (3.5,6.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (5.5,4.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (5.5,8.5) {\LARGE{\textbf{$\leftmoon$}}};
\node at (-0.7, 4.25) {36dm};
\node at (3.1, -0.5) {36dm};
\end{tikzpicture}
\end{center}
\end{document}
答案1
您还可以使用矩阵来简化代码。
\documentclass{exam}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{latexsym}
\usepackage{mathabx}
\usepackage{MnSymbol}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\def\B{\node[fill=black,text=white,minimum width=1cm,minimum height=1cm] {\LARGE$\leftmoon$};}%
\def\W{\node[fill=white,minimum width=1cm,minimum height=1cm] {\LARGE$\ostar$};}%
\node[matrix,draw=black,ultra thick,inner sep=1pt] (grid)
{
\W & \B & \W & \B & \W \\
\B & \W & \B & \W & \B \\
\W & \B & \W & \B & \W \\
\B & \W & \B & \W & \B \\
\W & \B & \W & \B & \W \\
\B & \W & \B & \W & \B \\
\W & \B & \W & \B & \W \\
\B & \W & \B & \W & \B \\
\W & \B & \W & \B & \W \\
};
\node[xshift=1cm,yshift=-.1cm,cylinder,rotate=90,
draw=black,thick,fill=gray,
minimum height=9.35cm,minimum width=2cm] at (grid.east) {};
\end{tikzpicture}
\end{center}
\end{document}
答案2
我必须承认,我的“圆柱体”看起来不太逼真,但无论如何,可以用更短的代码实现结果。如果你不明白什么,请随时提问,但我认为输入很多定义\node
变得乏味。
我保留了你的包列表,因为我不知道你是否在文档的其他地方使用它们,但其中许多对于此代码来说不是必需的。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{latexsym} %simbolos do Latex
\usepackage{bbm} %simbolos de conjuntos
\usepackage{pstricks}
\usepackage{pstricks-add, pst-eucl, here}
\usepackage{MnSymbol}
\usepackage{wasysym}
\usetikzlibrary{arrows.meta, patterns, shadings}
\begin{document}
\begin{tikzpicture}
\foreach \y [count=\nrow starting from 0] in {0,1,...,9} {
\foreach \x in {0,1,...,7} {
\pgfmathsetmacro\color{int(mod(\y + \x, 2)) ? "black" : "white"}
\fill[draw,fill=\color] (\x,\y) rectangle (\x+1,\y+1);
\ifnum\pdfstrcmp{\color}{white}=0
\node[font=\bfseries\LARGE] at (\x+.5,\y+.5) {$\ostar$};
\else
\node[font=\bfseries\LARGE, text=white] at (\x+.5,\y+.5) {$\leftmoon$};
\fi
}
}
\draw[left color=gray!50!black, right color=gray!50!black, middle color=gray!80, pattern color=black] (7.3,.3) --++ (0,9.7) arc (180:0:.7 and .3) -- (8.7,.3) -- cycle;
\fill[gray!30!black] (8,.25) ellipse (.7 and .3);
\draw[{Latex}-{Latex}] (0,-1) -- (8,-1) node[fill=white, midway] {60dm};
\draw[{Latex}-{Latex}] (-1,0) -- (-1,10) node[fill=white, midway] {36dm};
\end{tikzpicture}
\end{document}