我正在嘗試使用 tikx 在特定網格點為圖表序列繪製箭頭,但在嘗試使用以下命令時出現“非法測量單位(插入點)”:
\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}
, ie ,只包含數字。如果您在聲明中添加pt
after#1
和in ,它似乎有效。#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}