
draw
我在使用預定義命令時遇到了這個問題。知道如何修復嗎?這是一個最小的(不是)工作範例:
\documentclass{article}
\usepackage{tikz}
\newcommand{\Ve}{(1,1)}
\begin{document}
\begin{tikzpicture}
\draw (1,0) to[bend right] (1,1) ; %works
\draw \Ve to[bend right] (1,0) ; %works
\draw (1,0) to[bend right] \Ve ; %doesn't work
\end{tikzpicture}
\end{document}
產生的錯誤:
Latex Error: ./untitled.tex:9 Package tikz Error: (, +, coordinate, pic, or node expected. Latex Error: ./untitled.tex:9 Package pgf Error: No shape named is known.
答案1
你需要括號。應該繪製用\draw
例如兩個點指定的路徑。起始位置和結束位置的座標指定為圓括號。[看:2.3 直線路徑構建,第31頁]
定義:點位置
- 以公分為單位:
(1,0)
和(1,1)
這些位置是在一個特殊的座標系中指定的,其中最初的一個單位是
1cm
。 [看2.2.1 LATEX環境搭建第29-30頁] - in pt:
(1pt,0pt)
和(1pt,1pt)
-> 位置在有單位的特殊座標系內指定pt
。 - 在極座標中:
(0:1)
和(45:{sqrt(2)})
-> 極座標:1
分別sqrt(2)
(作為半徑)方向0
和45
角度(角度)。要計算{sqrt(2)}
(以獲得正確的半徑),您需要\usetikzlibrary{calc}
。2.15 指定座標,p37ff。 - with macro:
(\Va)
and -> TikZ 解析器透過明確尋找輸入流中的字元(\Ve)
來理解座標和節點(及其名稱) 。(
因此,如果括號隱藏在巨集內部,解析器首先無法找到括號,然後會展開宏,但為時已晚。相反,請使用\newcommand{\Va}{1,0}
and定義您自己的命令\newcommand{\Ve}{1,1}
(@JLDiaz 評論的提示)
但我更喜歡並推薦:
- with 座標:
(A)
和(B)
-> 定義兩個座標(名稱:A,乙)使用\coordinate
命令。例如\coordinate (A) at (1,0);
和\coordinate (B) at (1,1);
解決方案:
微量元素:
\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc}
%\newcommand{\Ve}{1,1}
\begin{document}
\begin{tikzpicture}
\coordinate (VE) at (1,1);
%\coordinate (VE) at (45:{sqrt(2)});
\draw (1,0) to[bend right] (1,1);
\draw (VE) to[bend right] (1,0);
\draw (1,0) to[bend right] (VE) ;
\end{tikzpicture}
% \begin{tikzpicture}
% \draw (1,0) to[bend right] (1,1);
% \draw (\Ve) to[bend right] (1,0);
% \draw (1,0) to[bend right] (\Ve) ;
% \end{tikzpicture}
\end{document}