我正在尝试使用以下代码绘制一批圆圈。但是,我无法创建我想要的图形。并且我收到一条错误消息undefined control sequence. argument 0,...,\NY
。但如果我将其更改\NY
为4
。它就可以正常工作。为什么我不能使用 \NY 呢{0,...,\NY}
?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usetikzlibrary{math}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
\tikzmath{
\VX = 30;
\VY = 30;
int \NX = 6;
int \NY = 4;
int \nix; int \niy;
\OX = 0; \OY = 0;
for \niy in {0,...,\NY}{%
for \nix in {0,...,6}{%
{\node [circle, draw = red, minimum size = \VX pt] at (\nix*\VX pt,\niy*\VY pt) {};};
};
};
};
\end{tikzpicture}
\end{document}
答案1
像
int \NY = 4;
不允许。使用
int \NY; \NY = 4;
相反,你的 MWE 将会起作用:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usetikzlibrary{math}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
\tikzmath{
\VX = 30;
\VY = 30;
int \NX; \NX = 6;
int \NY; \NY = 4;
int \nix; int \niy;
\OX = 0; \OY = 0;
for \niy in {0,...,\NY}{%
for \nix in {0,...,\NX}{%
{\node [circle, draw = red, minimum size = \VX pt] at (\nix*\VX pt,\niy*\VY pt) {};};
};
};
};
\end{tikzpicture}
\end{document}
答案2
或者,您可以\newcommand\NX{6}
\newcommand\NY{4}
在序言中使用它们,然后也可以在循环中使用它们。
梅威瑟:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usetikzlibrary{math}
\usetikzlibrary{positioning,calc}
\newcommand\NX{6}
\newcommand\NY{4}
\begin{document}
\begin{tikzpicture}
\tikzmath{
\VX = 30;
\VY = 30;
int \nix; int \niy;
\OX = 0; \OY = 0;
for \niy in {0,...,\NY}{%
for \nix in {0,...,\NX}{%
{\node [circle, draw = red, minimum size = \VX pt] at (\nix*\VX pt,\niy*\VY pt) {};};
};
};
};
\end{tikzpicture}
\end{document}