![错误“缺少 = 插入 \ifnum”](https://linux22.com/image/338000/%E9%94%99%E8%AF%AF%E2%80%9C%E7%BC%BA%E5%B0%91%20%3D%20%E6%8F%92%E5%85%A5%20%5Cifnum%E2%80%9D.png)
我正在尝试使用 \ifnum 来创建一个图形,但我一次又一次地收到该错误,不知道为什么,有人可以帮忙吗?这是我的代码:
\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\def \n {24}
\def \radius {6.5cm}
\def \nradius {0.2cm}
\def \margin {2} % margin in angles, depends on the radius
\definecolor{mycolor}{RGB}{254,199,184}
\foreach \s in {1,...,\n}
{
\node (\s) [circle, fill=mycolor, minimum width=\nradius] at ({360/\n * (\s - 1)+90}:\radius) {};
\node [fill=none, minimum width=\nradius] at ({360/\n * (\s - 1)+90}:\radius) {\footnotesize \s};
}
\foreach \s in {1,...,\n}
{
\pgfmathparse{\s+1} \let\ss\pgfmathresult
\pgfmathparse{\s+3} \let\sss\pgfmathresult
\foreach \k in {\ss,\sss,...,\n}{
\ifnum\k<25
\draw[->, >=latex, thick] (\s) -- (\k);
\fi
}
}
\end{tikzpicture}
\caption{\label{oclique24} Oriented version of the title page absolute o-clique}
\end{center}
\end{figure}
答案1
\pgfmathresult
2.0
第一个循环返回,其他循环类似,不是整数。使用\pgfmathtruncatemacro
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def \n {24}
\def \radius {6.5cm}
\def \nradius {0.2cm}
\def \margin {2} % margin in angles, depends on the radius
\definecolor{mycolor}{RGB}{254,199,184}
\foreach \s in {1,...,\n}
{
\node (\s) [circle, fill=mycolor, minimum width=\nradius] at ({360/\n * (\s - 1)+90}:\radius) {};
\node [fill=none, minimum width=\nradius] at ({360/\n * (\s - 1)+90}:\radius) {\footnotesize \s};
}
\foreach \s in {1,...,\n}
{
\pgfmathtruncatemacro{\ss}{\s+1}
\pgfmathtruncatemacro{\sss}{\s+3}
\foreach \k in {\ss,\sss,...,\n} {
\ifnum\k<25
\draw[->, >=latex, thick] (\s) -- (\k);
\fi
}
}
\end{tikzpicture}
\end{document}