
定義済みコマンドを使用するときにこの問題に遭遇しました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つの点を描画する必要があります。開始位置と終了位置の座標は、丸括弧。[見る:2.3 直線パスの構築、p.31]
意味:ポイント位置
- cm:
(1,0)
および(1,1)
位置は、最初は1単位が である特別な座標系内で指定されます
1cm
。[2.2.1 LATEXでの環境設定[p.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 座標の指定、p37以降。 - マクロ:
(\Va)
and(\Ve)
-> TikZ パーサーは、入力ストリーム内の文字を明示的に検索することで、座標とノード (およびその名前) を理解します。したがって、マクロ内に括弧が隠れている場合、パーサーは最初に括弧を見つけられず、次にマクロを展開しますが、これは手遅れになります。代わりに、 and を(
使用して独自のコマンドを定義します(ヒントは @JLDiaz のコメントから)\newcommand{\Va}{1,0}
\newcommand{\Ve}{1,1}
しかし、私は以下を好み、推奨します:
- 座標:
(A)
と(B)
-> 2つの座標の定義 (名前:あ、B)\coordinate
コマンドを使用します。例えば\coordinate (A) at (1,0);
、\coordinate (B) at (1,1);
解決:
MWE:
\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}