如果我执行以下代码,我会收到一条错误消息:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\begin{document}
\begin{tikzpicture}
\def\mytheta{23.43}
\draw (0, 0) -- (3, 0) -- (0, 1.3) -- cycle;
\draw (3,0) -- +(1, 1.2) -- ($ (0, 1.3)+(1, 1.2) $) -- (0, 1.3);
\draw (2.5, 0) arc (180:180-\mytheta:0.5);
\node at ($ (3,0) + (180- 0.5*\mytheta:0.7) $) {$\theta$};
\coordinate (origin) at (2.5, 1.2);
\draw[rotate=-\mytheta] (origin) -- +(0.6, 0) node[right] {$x$}
(origin) node[above] {$y$} -- + (0, -0.6) node[below] {$z$}
(origin) circle (1.5pt);
\fill (origin) circle (0.3pt);
\coordinate (apex) at (1,1.6);
\draw[dotted] (apex) -- +(10:0.4) coordinate (mup) (apex) -- +(-10:0.4) coordinate (mdown);
\draw (mup) -- +(10:0.4) (mdown) -- +(-10:0.4);
\draw ($ .5*(mup) + .5*(mdown) $) circle ({.2*tan(10)} and {.4*tan(10)});
\draw ($ (apex) + {(.8*tan(10), 0)} $) circle ({.4*tan(10)} and {.8*tan(10)});
\draw[dotted] (apex) -- +(-\mytheta:1) coordinate (Omega) (apex) -- +(180-\mytheta:0.2);
\draw ($ (Omega) + (-\mytheta-40:0.3) $) arc (-\mytheta-40:-\mytheta+40:0.2);
\node at ($ (Omega) + (-\mytheta:0.5) $) {$\Omega$};
\end{tikzpicture}
\end{document}
我该如何解决这个问题?也许问题出在代码的后半部分。
答案1
您的问题在于($ (apex) + {.8*tan(10)} $)
,因为这是在坐标上添加一个数字。我理解您的意思是写成($ (apex) + ({.8*tan(10)},0) $)
,在这种情况下,代码可以正常编译,输出为
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\begin{document}
\begin{tikzpicture}
\def\mytheta{23.43}
\draw (0, 0) -- (3, 0) -- (0, 1.3) -- cycle;
\draw (3,0) -- +(1, 1.2) -- ($ (0, 1.3)+(1, 1.2) $) -- (0, 1.3);
\draw (2.5, 0) arc (180:180-\mytheta:0.5);
\node at ($ (3,0) + (180- 0.5*\mytheta:0.7) $) {$\theta$};
\coordinate (origin) at (2.5, 1.2);
\draw[rotate=-\mytheta] (origin) -- +(0.6, 0) node[right] {$x$}
(origin) node[above] {$y$} -- + (0, -0.6) node[below] {$z$}
(origin) circle (1.5pt);
\fill (origin) circle (0.3pt);
\coordinate (apex) at (1,1.6);
\draw[dotted] (apex) -- +(10:0.4) coordinate (mup) (apex) -- +(-10:0.4) coordinate (mdown);
\draw (mup) -- +(10:0.4) (mdown) -- +(-10:0.4);
\draw ($ .5*(mup) + .5*(mdown) $) circle ({.2*tan(10)} and {.4*tan(10)});
\draw ($ (apex) + ({.8*tan(10)},0) $) circle ({.4*tan(10)} and {.8*tan(10)});
\draw[dotted] (apex) -- +(-\mytheta:1) coordinate (Omega) (apex) -- +(180-\mytheta:0.2);
\draw ($ (Omega) + (-\mytheta-40:0.3) $) arc (-\mytheta-40:-\mytheta+40:0.2);
\node at ($ (Omega) + (-\mytheta:0.5) $) {$\Omega$};
\end{tikzpicture}
\end{document}