我在制作大量 tikz 网格时遇到了问题。
我的代码如下:
\begin{tikzpicture}
\path[use as bounding box,draw] (12,18) rectangle (0,0);
\foreach \x in {0,2,4,8}
\draw[black] (0.999+\x,17) grid[step=0.2] (2+\x,15.999);
\draw[->] (3.5,15.5) -- (3.5,13);
\draw[->] (9.5,15.5) -- (9.5,13);
\foreach \x in {2,4,6,8}
\draw[black] (0.999+\x,12) grid[step=0.2] (2+\x,10.999);
\draw[->] (6.5,10) -- (6.5,9);
\draw[black] (5.999,8.100) grid[step=0.2] (7,7.099) node {};
\end{tikzpicture}
可以清楚地看到第三行的网格绘制不正确。
希望对大家有帮助。
答案1
如果您将网格定义为小图片pic
,那么您可以将 MWE 重写为:
\documentclass[tikz, margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[
GRID/.pic={\draw (0,0) grid[step=0.2] (1,1);}
]
\path[use as bounding box,draw] (12,18) rectangle (0,0);
\foreach \x in {1,3,5,9}
\pic at (\x,16) {GRID};
\draw[->] (3.5,15.5) -- (3.5,13);
\draw[->] (9.5,15.5) -- (9.5,13);
%\fill[red] (1,16) circle (1mm);% for test of pic coordinate
\foreach \x in {3,5,7,9}
\pic at (\x,11.5) {GRID};
\draw[->] (6.5,11) -- (6.5,9);
\pic at (6,7.5) {GRID};
\end{tikzpicture}
\end{document}
(图像不包含边界框)。