TikZ:使用角度庫

TikZ:使用角度庫

我正在嘗試使用該angles庫,但我不確定當從其他方法指定節點時如何應用它。

在範例中,向量的繪製和節點的命名發生在draw發出該angles指令的相同命令上。

\documentclass[tikz]{standalone}%

\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{angles}

\begin{document}
\begin{tikzpicture}
  \coordinate (O) at (0, 0);

  \path[name path = para] (-1, -2.5) parabola bend (2, 2) (4, 0);

  \draw (O) -- (5, 0) coordinate (P1);

  \path[name path = circ] (O) circle[radius = .75bp];
  \path[name intersections = {of = para and circ}];

  \coordinate (A) at (intersection-1);
  \coordinate (B) at (intersection-2);

  \draw[-latex, red] (A) -- ($(B)!1cm!(A)$) coordinate (P2);

  \path (P1) -- (O) -- (P2)
  pic[''$\theta$'', draw, -latex, red, angle radius = .5cm,
  angle eccentricity = 1.2] {angle = P1--O--P2};
\end{tikzpicture}
\end{document}

它告訴我 theta 不是一種顏色。


即使我加載quotes庫並像 Harish Kumar 回答的那樣加雙引號\theta,我仍然收到訊息:

! Missing \endcsname inserted.
<to be read again>
                   \theta
l.41   angle eccentricity = 1.2, font = \tiny]
                                               {angle = P1--O--P2};
! Missing \endcsname inserted.

 ...

l.41 ...y = 1.2, font = \tiny] {angle = P1--O--P2}
                                                  ;

! Package xcolor Error: Undefined color ```$\theta $'''.

對於那些不相信我雙引號引起同樣問題的人,我為您講述了一個視頻,表明情況確實如此。

https://www.dropbox.com/s/44zhedz2psg1vrk/2014-05-08%2018.08.46.mp4

答案1

您需要載入quotes庫才能使用quotes語法。這啟用了標籤、引腳、邊緣節點和圖片文字的引號語法。

另外,它是雙引號,例如"$\theta$"(not ''$\theta$'')。某些編輯器(例如 Emacs)會自動轉換"``or ''(取決於它們是插入在單字的開頭還是結尾),因為這會在編譯文件後產生正確的輸出。然而,在這種情況下,我們想要實際的雙引號。要在 Emacs 中輸入這些內容,只需按雙引號鍵即可兩次陸續。第二個會將之前插入的兩個單引號轉換為一個雙引號,這就是這裡所需要的。

\documentclass[tikz,varwidth]{standalone}%

\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{angles}
\usetikzlibrary{quotes}

\begin{document}
\begin{tikzpicture}
  \coordinate (O) at (0, 0);

  \path[name path = para] (-1, -2.5) parabola bend (2, 2) (4, 0);

  \draw (O) -- (5, 0) coordinate (P1);

  \path[name path = circ] (O) circle[radius = .75bp];
  \path[name intersections = {of = para and circ}];

  \coordinate (A) at (intersection-1);
  \coordinate (B) at (intersection-2);

  \draw[-latex, red] (A) -- ($(B)!1cm!(A)$) coordinate (P2);

  \path (P1) -- (O) -- (P2) pic["$\theta$", draw,-latex, red, angle radius = 0.5cm, angle eccentricity = 1.2] {angle = P1--O--P2};
\end{tikzpicture}
\end{document}

在此輸入影像描述

答案2

如果包含 Quotes 庫仍然沒有解決問題,我建議加載 babel 庫,因為它是建議的這裡。我遇到了完全相同的問題,它對我有用。

\usetikzlibrary{angles,quotes}
\usetikzlibrary{babel}

答案3

在某些非英語語言的文檔中使用quote庫會出現 babels 重新定義的問題''。例如(稍作修改用戶11232答):

\documentclass[tikz, margin=3mm]{standalone}%
\usetikzlibrary{angles,
%                babel, % <-- example works if you enable this library
                calc,
                intersections,
                quotes}
\usepackage[slovene]{babel}
\begin{document}
    \begin{tikzpicture}[
              > = stealth,
   angle radius = 5mm,
my angle/.style = {draw, -latex,
                   angle eccentricity=1.3,
                   font=\large} % angle label position!
                        ]
\draw   (0,0) coordinate (O) -- 
        (4,0) coordinate (P1);
\draw[very thin, dashed, name path = para] (-1,-2.5) parabola bend (2,2) (4,0);
\draw[very thin, name path = circ] (O) circle[radius = .75bp];
%
\path[name intersections = {of = para and circ, by={A,B}}];
%
\draw[-latex, red] (A) -- ($(B)!1cm!(A)$) coordinate (P2);
%
\path (P1) -- (O) -- (P2) 
    pic[my angle,"$\theta$"] {angle = P1--O--P2};
\end{tikzpicture}
\end{document}

給出錯誤:

! Argument of \language@active@arg" has an extra }.
<inserted text> 
                \par 
l.26     pic[my angle,"$\theta$"]
                                  {angle = P1--O--P2};
? x

如果我babel在上述 MWE 的序言中啟用庫,則會消失並給出以下結果:

在此輸入影像描述

讓我指出,這個問題已在此處的許多問題/答案中討論過。此外,OP MWE 的計算要求非常高,需要一段時間才能給出結果。對於它的問題有更好的方法(但這不是這裡的問題)。

相關內容