Tikz 变量错误

Tikz 变量错误

这是我使用foreach循环的最小代码:

%Creation of Arduino Pins
            \foreach \x in {1,...,22}
                {\draw($(arduino.north east)!\x/25 + 2/25!(arduino.south east)$)node[label={[font=\footnotesize]left:\x}](arduinoPin\x){};}

以下是我想做的事情:

\pgfmathsetmacro\numpins{25}
            %Creation of Arduino Pins
            \foreach \x in {1,...,\numpins - 3}
                {\draw($(arduino.north east)!\x/\numpins + 2/\numpins!(arduino.south east)$)node[label={[font=\footnotesize]left:\x}](arduinoPin\x){};}

我收到以下错误:

Illegal unit of measure (pt inserted). Missing = inserted for \ifdim.

有人能帮我看看这个变量或者别的什么是怎么回事吗?

答案1

您需要有一些评估整数。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
    \node[minimum height=10cm](arduino){};
    \pgfmathtruncatemacro\numpins{25}
    %Creation of Arduino Pins
    \foreach \x in {1,...,\the\numexpr\numpins-3}
    {\draw($(arduino.north east)!\x/\numpins + 2/\numpins!(arduino.south east)$)
     node[label={[font=\footnotesize]left:\x}](arduinoPin\x){};}
\end{tikzpicture}
\end{document}

相关内容