無法從 pgfmanual 編譯基本 tikz 程式碼

無法從 pgfmanual 編譯基本 tikz 程式碼

上學期,我開始只使用 LaTeX 來做功課和家庭作業,但現在我想更上一層樓。

tikz我按照 pgfmanual從庫開始。每次我嘗試編譯程式碼時,我都會從文檔中得到不同的結果,或者甚至無法編譯。

例如,我從文件中直接複製了第一個程式碼

    \documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=stealth, scale=3] 

    \clip (-2, -0.2) rectangle (2,0.8);
    \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
    \draw[<->](-1.5, 0) -- (1.5,0);
    \draw[<->](0, -1.5) -- (0, 1.5);
    \draw (0,0) circle [radius=1cm];

    \draw[very thick,red]
        (30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- x axis);
    \draw[very thick blue]
        (30:1cm |- x axis) -- node[below=2pt,fill=white] {$\cos \alpha$} (0,0);

    \filldraw[fill=green!20!white, draw=green!50!black] (0,0) -- (3mm,0mm)
        arc [start angle=0, end angle=30, radius=3mm] --cycle;
    \foreach \x\xtext in {-1,-0.5/-\frac{1}{2}, 1}
        \draw (\x cm, 1pt) -- (\x cm, -1pt) node [anchor=north] {$\xtext$};
    \foreach \y/\ytext in {-1,-0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1}
        \draw (1pt, \y cm) -- (-1pt, \y cm) node [anchor=east] {$\ytext$};


    \path [name path=upward line] (1,0) -- (1,1);
    \path [name path=sloped line] (0,0) -- (30:1.5cm);
    \draw [name intersections={of=upward line and sloped line, by=t}]
            [very thick, orange]  (1,0) -- node [right=1pt,fill=white];
            {$\displaystyle \tan \alpha \color{black} =
                \frac{{\color{red}\sin \alpha}}{\color{blue} \cos \alpha}$} (t);


\end{tikzpicture}


\end{document}

這是我編譯時的結果:

編譯該程式碼後的結果

這是文件中顯示的結果在此輸入影像描述

作業系統:Ubuntu 18.04 LTS 我已經在上面安裝了 Texlive iso。

答案1

您不能只是複製並貼上手冊中的程式碼範例。實際上,您必須閱讀手冊才能了解如何使用範例。在這種情況下,你失蹤了\usetikzlibrary{intersections}

這是教程中的相關部分:

在此輸入影像描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=3]
  \clip (-2,-0.2) rectangle (2,0.8);
  \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
  \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
    arc [start angle=0, end angle=30, radius=3mm] -- cycle;
  \draw[->] (-1.5,0) -- (1.5,0) coordinate (x axis);
  \draw[->] (0,-1.5) -- (0,1.5) coordinate (y axis);
  \draw (0,0) circle [radius=1cm];

  \draw[very thick,red]
    (30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- x axis);
  \draw[very thick,blue]
    (30:1cm |- x axis) -- node[below=2pt,fill=white] {$\cos \alpha$} (0,0);
  \path [name path=upward line] (1,0) -- (1,1);
  \path [name path=sloped line] (0,0) -- (30:1.5cm);
  \draw [name intersections={of=upward line and sloped line, by=t}]
    [very thick,orange] (1,0) -- node [right=1pt,fill=white]
    {$\displaystyle \tan \alpha \color{black}=
      \frac{{\color{red}\sin \alpha}}{\color{blue}\cos \alpha}$} (t);

  \draw (0,0) -- (t);

  \foreach \x/\xtext in {-1, -0.5/-\frac{1}{2}, 1}
    \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north,fill=white] {$\xtext$};
  \foreach \y/\ytext in {-1, -0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1}
    \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east,fill=white] {$\ytext$};
\end{tikzpicture}
\end{document}

相關內容