使用let指令繪製帶有旋轉角度的單箭頭形狀

使用let指令繪製帶有旋轉角度的單箭頭形狀

我找到了一個很好的範例程式碼這裡,並嘗試用let命令重新格式化它並定義一個newcommand以便於使用。

以下是我的草稿版本,但無法通過編譯:

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows, calc}
\newcommand{\dbarr}[4] {
  \path (#1) -- (#2) 
    let 
        \p1=($(#1) - $(#2)),
        \n{height}={veclen(\x1,\y1)}, 
        \n{angle}={atan2(\y1,\x1)} in 
    node[midway, single arrow, draw=black, 
        minimum width=15mm, minimum height=\n{height}, 
        inner sep=0mm, single arrow head extend=1mm, double arrow head extend=1mm,
        fill=cyan!20,double arrow,rotate=\n{angle}] (#3) {#4};    
}
\begin{document}
    \begin{tikzpicture}
    \coordinate (A) at (0,0);
    \coordinate (B) at (2,2);
    \dbarr{A}{B}{C}{from A to B};
    \end{tikzpicture}
\end{document}

錯誤:

Runaway argument?
$(B)), \n {height}={veclen(\x 1,\y 1)}, \n {angle}={atan2(\y 1,\x 1)}\ETC.
! File ended while scanning use of \tikz@cc@parse@factor.
<inserted text> 
                \par 
<*> a.tex
         
? x
No pages of output

這個錯誤讓我很難理解錯誤在哪裡。如果有人能幫助我,我將不勝感激!

答案1

\p1=($(#1) - $(#2))如果替換為\p1=($(#1) - (#2)$)(注意 的位置),則程式碼將編譯$

相關內容