我想在一个图形上规则地间隔开对象,但让一些网格位置保持空白。下面的方法 1 有效,但很难让网格位置保持空白(我猜需要一些复杂的逻辑)。方法 2(尝试对坐标使用 foreach,然后将这些坐标缩放并偏移到我的网格上)不起作用,我收到! Dimension too large. <recently read> \pgfmath@x [...]. I can't work with sizes bigger than about 19 feet.
错误。我该如何让它工作?
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\newlength{\step}
\setlength{\step}{2.618cm}
\def\cols{14}
\def\rows{14}
\def\side{4\step}
\def\sep{1\step}
\def\half{0.5*\side}
\def\bottom{0}
\def\left{0}
\centering
\begin{tikzpicture}[draw,color=black!30]
% grid
\draw[step=\step, line width=3pt] (0cm,0cm) grid (\step*\cols,\step*\rows);
% method 1
\foreach \y in {0,...,2}{%
\foreach \x in {0,...,2}{%
\coordinate (m) at (
\left+\half+\x*\side+\x*\sep,
\bottom+\half+\y*\side+\y*\sep
);
\draw[fill=black] (m) circle (21.5mm);
\draw[fill=white] (m) circle (11.5mm);
\draw[fill=black] (m) circle (1.5mm);
}
};
% method 2
\foreach \xy in {(0,0),(1,1),(2,0)}{%
\path let \p1 = \xy in coordinate (m2) at (
\left+\half+\x1*\side,
\bottom+\half+\y1*\side
);
\draw[fill=black] (m2) circle (21.5mm);
\draw[fill=white] (m2) circle (11.5mm);
\draw[fill=black] (m2) circle (1.5mm);
};
\end{tikzpicture}
\end{document}
答案1
欢迎来到 TeX.SE!!
我不明白你想做什么,我认为这可能是缩放和偏移对象的更好方法。
无论如何,您可以轻松修改方法 2,如下所示:
\documentclass[tikz]{standalone}
\begin{document}
\newlength{\step}
\setlength{\step}{2.618cm}
\def\cols{14}
\def\rows{14}
\def\side{4\step}
\def\sep{1\step}
\def\half{0.5*\side}
\def\bottom{0}
\def\left{0}
\begin{tikzpicture}[draw,color=black!30]
% grid
\draw[step=\step, line width=3pt] (0cm,0cm) grid (\step*\cols,\step*\rows);
% method 2 modified
\foreach \x/\y in {0/0,1/1,2/0} {%
\draw[fill=black] (\left+\half+\x*\side,\bottom+\half+\y*\side) circle (21.5mm);
\draw[fill=white] (\left+\half+\x*\side,\bottom+\half+\y*\side) circle (11.5mm);
\draw[fill=black] (\left+\half+\x*\side,\bottom+\half+\y*\side) circle (1.5mm);
};
\end{tikzpicture}
\end{document}