我正在嘗試使用以下程式碼繪製一批圓圈。然而,我沒能創造出我想要的圖形。我收到一個錯誤說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}