![在同一张 tikzpicture 中绘制 4 个相同的图形](https://linux22.com/image/394322/%E5%9C%A8%E5%90%8C%E4%B8%80%E5%BC%A0%20tikzpicture%20%E4%B8%AD%E7%BB%98%E5%88%B6%204%20%E4%B8%AA%E7%9B%B8%E5%90%8C%E7%9A%84%E5%9B%BE%E5%BD%A2.png)
我已经成功使用以下代码制作了一个六边形:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=2,cap=round,>=latex]
\newdimen\R
\R=0.8cm
\coordinate (center) at (0,0);
\draw (0:\R)
\foreach \x in {60,120,...,360} { -- (\x:\R) }
-- cycle (300:\R) node[below] {}
-- cycle (240:\R) node[below] {}
-- cycle (180:\R) node[left] {}
-- cycle (120:\R) node[above] {}
-- cycle (60:\R) node[above] {}
-- cycle (0:\R) node[right] {};
\draw { (60:\R) -- (30:0.69) -- (center) -- (60:\R) } [fill=gray];
\draw { (90:0.69) -- (120:\R) -- (center) -- (90:0.69) } [fill=gray];
\draw { (180:\R) -- (150:0.69) -- (center) -- (180:\R) } [fill=gray];
\draw { (240:\R) -- (210:0.69) -- (center) -- (240:\R) } [fill=gray];
\draw { (300:\R) -- (270:0.69) -- (center) -- (300:\R) } [fill=gray];
\draw { (0:\R) -- (330:0.69) -- (center) -- (0:\R) } [fill=gray];
\end{tikzpicture}
\end{figure}
\end{document}
它画出了这个:
但当我尝试做 4 个时,对我来说真的很复杂,请帮忙。谢谢
答案1
通常建议使用pic
s,但在这里您可以使用稍微扩展的标准节点。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\tikzset{repeating shape/.style={regular polygon,regular polygon sides=#1,alias=curr,draw,append after command={
[draw,] foreach \XX [remember=\XX as \YY (initially #1)]
in {1,...,#1} {
(curr.corner \XX) -- (curr.center) -- ($(curr.corner \YY)!0.5!(curr.corner
\XX)$)}}}}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=2]
\draw[fill=gray] foreach \X in {0,2.2} { foreach \Y in {0,2.2}
{(\X,\Y) node[repeating shape=6,minimum size=3cm]{} }};
\end{tikzpicture}
\end{figure}
\end{document}
答案2
没有人会阻止您pic
,并且拥有尽可能多的选择。
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\newdimen\R
\R=0.8cm
\tikzset{
pics/hexagon/.style args={#1 and #2}{
code={
\node[regular polygon,regular polygon sides=6,minimum size=2*\R] (x) {};
\coordinate (x.corner 0) at (x.corner 6);
\foreach \i in {0,...,5} {
\fill[#1] (x.center) -- (x.{\i*60}) -- (x.{\i*60+30});
\fill[#2] (x.center) -- (x.{\i*60-30}) -- (x.{\i*60});
}
}
}
}
\begin{document}
\begin{tikzpicture}
\pic at (-1,-1) {hexagon=gray and black};
\pic at (-1, 1) {hexagon=gray and black};
\pic at ( 1,-1) {hexagon=gray and black};
\pic at ( 1, 1) {hexagon=gray and black};
\end{tikzpicture}
\end{document}
答案3
这是一个简单的方法!
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\a{2}
\def\subpic{
\fill[gray] (0:\a)--(60:\a)--(120:\a)
--(180:\a)--(240:\a)--(300:\a)--cycle;
\foreach \i in {0,1,...,5}
\fill[rotate=60*\i] (0,0)--(120:\a)-|cycle;
}
\foreach \j in {45,135,-135,-45}{
\begin{scope}[shift={(\j:4)}]
\subpic
\end{scope}
}
\end{tikzpicture}
\end{document}