我正在尝试在 tikz 中绘制两条线之间的角度圆弧。我正在使用角度库,并且基本上复制了手册中的示例,但是当我尝试标记圆弧时,出现以下错误:
! Missing \endcsname inserted.
<to be read again>
\theta
l.29 ...c [draw, "$\theta$", angle eccentricity=3]{angle=P--V--Q};
删除标签后,我可以轻松绘制弧线。但我真的很想在图表中放置一个 theta。我认为这可能是转义问题,所以我尝试使用 进行标记"$t$"
,然后"t"
。在最后一种情况下,错误告诉我 tikz 不知道标签t
。
我的绘图代码如下
\documentclass[border=20pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles}
\begin{document}
\begin{tikzpicture}
\def \radius{3.5}
\coordinate (V) at ($(0,0)!\radius cm!rand*45:(0,\radius)$);
\path (-\radius, 0) coordinate(P) --
coordinate[midway](O)
(\radius, 0) coordinate(Q);
% Draw semicircle
\draw (Q) arc(0:180:\radius1);
\draw[shorten <=-5mm, shorten >=-5mm] (P) -- (Q);
%draw an arc starting at [partway from V to Q], to[ partway from V to P]
\draw [color=blue] (P)--(V)--(Q);
\pic [draw, "$\theta$", angle eccentricity=3] {angle=P--V--Q};
\node at (O) [below] {$O$};
\node at (P) [below] {$P$};
\node at (Q) [below] {$Q$};
\node at (V) [above] {$V$};
\foreach \p in {O,P,Q, V}{
\fill (\p) circle (1pt);
}\
\end{tikzpicture}
\end{document}
答案1
您的问题已由@Roland 评论解决,因此这里有一些题外的建议:
\documentclass[border=20pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,
calc,
quotes} % <---
\begin{document}
\begin{tikzpicture}
\def \radius{3.5}
\coordinate (V) at ($(0,0)!\radius cm!rand*45:(0,\radius)$);
\path (-\radius, 0) coordinate[label=below:$P$] (P) % <---
-- coordinate[label=below:$O$] (O) (\radius, 0) % <---
coordinate[label=below:$Q$] (Q); % <---
% draw semicircle
\draw (Q) arc(0:180:\radius);
\draw[shorten <=-5mm, shorten >=-5mm] (P) -- (Q);
% draw triangles's cathetus
\draw [color=blue, semithick] (P)--(V)--(Q);
% draw angle
\pic [draw=blue, text=red, "$\theta$", angle eccentricity=1.5] {angle=P--V--Q}; % <---
% dots
\foreach \p in {O,P,Q, V}{\fill (\p) circle[radius=1.5pt];}
\end{tikzpicture}
\end{document}
编辑:正如您在评论中所希望的那样,彩色角度。
答案2
即使前面的答案是如此简洁的解决方案,我认为您肯定会发现该tkz-euclide
软件包在绘制数学几何图形时非常灵活。我没有用tkz-euclid
命令重写您的所有图形,但您可以通过这样做来节省您未来项目的时间。这里,唯一的变化是绘制和标记角度。
\documentclass[border=20pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\def \radius{3.5}
\coordinate (V) at ($(0,0)!\radius cm!rand*45:(0,\radius)$);
\path (-\radius, 0) coordinate(P) --
coordinate[midway](O)
(\radius, 0) coordinate(Q);
% Draw semicircle
\draw (Q) arc(0:180:\radius1);
\draw[shorten <=-5mm, shorten >=-5mm] (P) -- (Q);
%draw an arc starting at [partway from V to Q], to[ partway from V to P]
\draw [color=blue] (P)--(V)--(Q);
%-------------- Here's the use of tkz-euclide-----
\tkzMarkAngle[color=blue,mark=none,size=.5](P,V,Q)
\tkzLabelAngle[color=red,pos=0.8](P,V,Q){$\theta$}
%-------------------------------------------------
\node at (O) [below] {$O$};
\node at (P) [below] {$P$};
\node at (Q) [below] {$Q$};
\node at (V) [above] {$V$};
\foreach \p in {O,P,Q, V}{
\fill (\p) circle (1pt);
}\
\end{tikzpicture}
\end{document}