上个学期,我开始使用 LaTeX 来完成作业和家庭作业,但现在我想要更上一层楼。
我按照 pgfmanual 开始使用该tikz
库。每次我尝试编译代码时,都会得到与文档不同的结果,甚至无法编译。
例如第一个代码是我直接从文档中复制的
\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}