TikZ中节点名称的模块化算法? [英] Modular arithmetic on node names in TikZ?

查看:98
本文介绍了TikZ中节点名称的模块化算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想在TikZ中构建一个循环图,其中选择的n个(例如5个)标记为v0,v1,...,v_n-1的节点数目可变.

Say I want to construct a circulant graph in TikZ, with a variable number of nodes, labelled v0, v1, ..., v_n-1 for some n of my choice (say, 5).

我希望能够在TikZ中使用\ foreach命令来迭代(1)定义节点,以及(2)连接节点.我希望能够将v_i连接到v_(i + 1),并将v_i连接到v_ {i + 2}.

I'd like to be able to use the \foreach command in TikZ to iteratively (1) define the nodes, and (2) connect the nodes. I'd like to be able to connect v_i to v_(i+1) and v_i to v_{i+2}, say.

\foreach \i in {0, ..., 4} {\path (\i*72:3) node (v\i) {};}

\foreach \i in {0, ..., 4} {\path (\i*72:3) node (v\i) {};}

完美地构建节点.但是当我想画线时,

constructs the nodes perfectly. But then when I want to draw some lines,

\foreach \i \in {0, ..., 3} { \draw (v\i) -- (v{\i+1}); } ????

\foreach \i \in {0, ..., 3} { \draw (v\i) -- (v{\i+1}); } ????

不起作用.也不

\foreach \i / \j in {0/1, ..., 3/4} { \draw (v\i) -- (v{\j}); }

\foreach \i / \j in {0/1, ..., 3/4} { \draw (v\i) -- (v{\j}); }

我收到错误消息没有这样的形状v0"或类似的东西.

I get an error "no such shape v0" or something like that.

我知道这一定很容易做到,但是我不知道怎么做.有什么建议吗?

I know this must be totally easy to do, but I can't figure out how. Any suggestions?

作为后续,很高兴能够使用单个\foreach命令连接v_i和v_ {i + 4}或其他东西,并让TikZ/pgf为我执行模块化算法,而不必担心关于溢出.

As a followup, it would be nice to be able to connect v_i and v_{i+4} or something, with a single \foreach command, and have TikZ/pgf do the modular arithmetic for me without having to worry about spilling over.

推荐答案

另一种解决方案,由Steve Tjoa实现了对代码的

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}

这篇关于TikZ中节点名称的模块化算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆