我正在使用 tikz 绘制数学结构。我已经在代码中标记了所有节点,我想将它们用作 \draw 命令中的参数,但我一直收到此错误“!缺少 \endcsname 插入。”下面是一个最低限度的工作示例。请帮助我。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
Putting node and clipping them to their respective positions
\foreach \x in {2,3,4,...,14}
\foreach \y in {2,3,4}
{
\node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.8mm] (u\x\y) at (\x,\y) {};
}
%Drawing arrows
\foreach \x in {3,5,...,11}
{
\v = \x + 1;
\draw[->>] (u\x3) -- (u\v2) ;
}
\end{tikzpicture}
\end{document}
答案1
这是没有额外变量的另一种选择:
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Putting node and clipping them to their respective positions
\foreach \x in {2,3,4,...,14}
\foreach \y in {2,3,4}
{
\node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.8mm] (u\x\y) at (\x,\y) {};
}
%Drawing arrows
\foreach \x in {3,5,...,11}
{
\draw[->>] (u\x3) -- (u\number\numexpr\x+1\relax2) ;
}
\end{tikzpicture}
\end{document}
答案2
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Putting node and clipping them to their respective positions
\foreach \x in {2,3,4,...,14}
\foreach \y in {2,3,4}
{
\node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.8mm] (u\x\y) at (\x,\y) {};
}
%Drawing arrows
\foreach \x in {3,5,...,11}
{
\pgfmathparse{\x+1}
\pgfmathtruncatemacro{\v}{\pgfmathresult}
\draw[->>] (u\x3) -- (u\v2) ;
}
\end{tikzpicture}
\end{document}