![使用列表中的节点进行循环绘制](https://linux22.com/image/367315/%E4%BD%BF%E7%94%A8%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9%E8%BF%9B%E8%A1%8C%E5%BE%AA%E7%8E%AF%E7%BB%98%E5%88%B6.png)
下面的代码归功于 Jerome Tremblay,原始代码可以在这里找到这里
% A simple cycle
% Author : Jerome Tremblay
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\def \n {5}
\def \radius {3cm}
\def \margin {8} % margin in angles, depends on the radius
\foreach \s in {1,...,\n}
{
\node[draw, circle] at ({360/\n * (\s - 1)}:\radius) {$\s$};
\draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\end{tikzpicture}
\end{document}
一切都运行正常,直到我想使用其他节点,例如来自此列表的节点
{a,b,c,d,e,f,g,h,i}
应该是排版的,而不是按数字排序的节点。你能帮忙吗?
答案1
好,我知道了。
\begin{tikzpicture}
\def \n {9}
\def \radius {3cm}
\def \margin {8} % margin in angles, depends on the radius
\foreach \s in {1,...,\n}
{
\draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\foreach \t [count=\i] in {a,b,c,d,e,f,g,h,i}
{
\node[draw, circle] at ({360/\n * (\i - 1)}:\radius) {\t};
}
\end{tikzpicture}