在 tikz 中使用 ifthenelse 和 mod 函数时出现错误

在 tikz 中使用 ifthenelse 和 mod 函数时出现错误

我收到此乳胶代码的错误,请有人能帮助我

 \documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{graphs,graphs.standard,arrows.meta}

\begin{document}

\newcount\mycount
\begin{tikzpicture}
  \SetGraphUnit{2}
  \renewcommand*{\VertexLineColor}{white}
  \renewcommand*{\VertexLightFillColor}{red}
  \renewcommand*{\VertexLineWidth}{1pt}
  \GraphInit[vstyle=Welsh]
  \Vertices{circle}{1,...,7}
  \AddVertexColor{blue}{1,5}
  \SetUpEdge[style={->,very thick},color=red]
  \foreach \i in {1,...,7}
  { 
    \foreach \j in {1,2,3}
    { 
      \mycount=\i+\j
      \pgfmathparse{int(Mod(\mycount,7))}
      \ifthenelse{\pgfmathresult=0}
      { 
        \Edge(\i)(\mycount)
      }  
      { \edef\k{\pgfmathresult}
    \Edge(\i)(\k)
      }
    };
  };
\end{tikzpicture}
\begin{document}

我确实想绘制一个名为常规局部传递锦标赛的锦标赛。每个节点“i”必须通过边与 i+1、i+2、i+3 相关,并通过 mod 函数测试是否具有圆形。提前致谢!

答案1

这能达到你想要的效果吗?

在此处输入图片描述

\documentclass{article}
\usepackage{tkz-graph}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
  \SetGraphUnit{2}
  \renewcommand*{\VertexLineColor}{white}
  \renewcommand*{\VertexLightFillColor}{red}
  \renewcommand*{\VertexLineWidth}{1pt}
  \GraphInit[vstyle=Welsh]
  \Vertices{circle}{1,2,3,4,5,6,7} % the ... syntax doesn't work here
  \AddVertexColor{blue}{1,5}
  \SetUpEdge[style={->,very thick},color=red]
  \foreach \i in {1,...,7}
  { 
    \foreach
    [evaluate=\j as \k using {ifthenelse(Mod(\i+\j,7)==0,int(\i+\j),int(Mod(\i+\j,7)))}]
     \j in {1,2,3}
    { 
     \Edge(\i)(\k)
      }
    }
\end{tikzpicture}
\end{document}

相关内容