Modular arithmetic on node names in TikZ?

白昼怎懂夜的黑 提交于 2019-12-02 00:11:02

This worked for me:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,fit,arrows,positioning}
\tikzstyle{vertex} = [circle, draw, thick, text centered]
\tikzstyle{edge} = [draw, thick,->]
\begin{document}
\begin{tikzpicture}[scale=1]
  \foreach \x in {0,...,6}
    \node[vertex] (\x) at (\x*360/7:3) {v\x};
  \foreach \x/\y in {0/1,1/2,2/3,3/4,4/5,5/6,6/0}
    \draw[edge] (\x) to (\y);
\end{tikzpicture}
\end{document}

The syntax {0/1,...,5/6} did not work for me. But I admit, I spent a bit of time trying to find a good solution, and I'm still not totally satisfied.

Another solution, achieved editing the code by Steve Tjoa:

\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[thick]
\foreach \x in {0,...,4}{%
  \node [circle, draw] at (\x*72:3) {$v_{\x}$};
  \draw [->] (\x*72+10:3) arc (\x*72+10:\x*72+62:3);
}
\end{tikzpicture}
\end{document}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!