我正在尝试使用 tikx 在图表序列的特定网格点处绘制箭头,但是当我尝试使用以下命令时出现“非法测量单位(插入 pt)”:
\newcommand*{\drawhigharrow}[2]{
\ifdim #1 < #2 {
\draw (#1*\gridsize+0.5*\gridsize, 5*\gridsize) edge[thick,out=90,in=180] (#2*\gridsize, 6*\gridsize);
\draw (#2*\gridsize, 6*\gridsize) edge[thick, out=0,in=90,->] (#2*\gridsize+0.5*\gridsize, 5*\gridsize+0.1);
} \else {
\draw (#1*\gridsize+0.5*\gridsize, 5*\gridsize) edge[thick, out=90,in=0] (#1*\gridsize, 6*\gridsize);
\draw (#1*\gridsize, 6*\gridsize) edge[thick, out=180,in=90,->]
(#2*\gridsize+0.5*\gridsize, 5*\gridsize+0.1);
}
\fi
}
抱歉,我问了,但我不知道哪里出了问题——计算似乎都很标准(只是乘法和加法)。有人能帮我找出我的错误吗?
欢呼吧,托马斯
答案1
\ifdim
用于比较尺寸/长度。假设您使用类似 的命令\drawhigharrow{1}{2}
,即仅使用数字。如果您在语句pt
后添加#1
and ,它似乎有效。#2
\ifdim
或者,您可以使用\ifnum #1 < #2
,在这种情况下比较的是数字。
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\newcommand\gridsize{1cm}
\newcommand*{\drawhigharrow}[2]{
\ifdim #1pt < #2pt { % note the addition of pt
\draw (#1*\gridsize+0.5*\gridsize, 5*\gridsize) edge[thick,out=90,in=180] (#2*\gridsize, 6*\gridsize);
\draw (#2*\gridsize, 6*\gridsize) edge[thick, out=0,in=90,->] (#2*\gridsize+0.5*\gridsize, 5*\gridsize+0.1);
} \else {
\draw (#1*\gridsize+0.5*\gridsize, 5*\gridsize) edge[thick, out=90,in=0] (#1*\gridsize, 6*\gridsize);
\draw (#1*\gridsize, 6*\gridsize) edge[thick, out=180,in=90,->]
(#2*\gridsize+0.5*\gridsize, 5*\gridsize+0.1);
}
\fi
}
\begin{document}
\begin{tikzpicture}
\drawhigharrow{1}{2}
\end{tikzpicture}
\end{document}