@u4830 你所给MWE没有使用markdown语法...
tikz
的子库必须使用新版本的TeXLive
编译,不可以使用CTeX
套装。
关键的问题在于,其中的定义函数名不符合要求,不可以使用数字作为宏的名称(参考阅读):
于是只要将:
\newcommand{\LongitudePlane3}[3]{%
...
}
\newcommand{\LatitudePlane3}[3]{%
...
}
\newcommand{\DrawLongitudeCircle2}[2]{%
...
}
\newcommand{\DrawLatitudeCircle2}[2]{%
...
}
中自定义命令末尾的数字3
以及2
替换为符合要求的即可:
例如:
\newcommand{\LongitudePlaneThree}[3]{%
\pgfmathsinandcos\sinEl\cosEl{#2}
\pgfmathsinandcos\sint\cost{#3}
\tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}
\newcommand{\LatitudePlaneThree}[3]{%
\pgfmathsinandcos\sinEl\cosEl{#2} % elevation
\pgfmathsinandcos\sint\cost{#3} % latitude
\pgfmathsetmacro\yshift{\cosEl*\sint}
\pgfmathsetmacro\yshift{\cosEl*\sint}
}
\newcommand{\DrawLongitudeCircleTwo}[2]{%
\LongitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}% angle of "visibility"
\pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
\draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
\draw[current plane, dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}
\newcommand{\DrawLatitudeCircleTwo}[2]{%
\LatitudePlane{\angEl}{#2}
\tikzset{current plane/.prefix style={scale=#1}}
\pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}% angle of "visibility"
\pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
\draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
\draw[current plane, dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}
同时OP提供的代码宏包使用非常混乱,有大量过时老旧的宏包以及大量的重复调用的情况,应该仔细理清每一个提供的具体功能,而不是大量复制代码然后简单堆砌在一起,这是非常不好的习惯,不要不厌其烦地三番五次调用同一个库,很容易导致你大量代码混杂,同时无法提供M(Minimal)WE。你的代码完全可以只通过如下的代码实现:
\documentclass{ctexbook}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}[scale=.75]
% Define radius
\def\r{3}
% Bloch vector
\draw (0,0) node[circle,fill,inner sep=1] (orig) {} -- (\r/3,\r/2) node[circle,fill,inner sep=0.7,label=above:$\vec{r}$] (a) {};
\draw[dashed] (orig) -- (\r/3,-\r/5) node (phi) {} -- (a);
% Sphere
\draw (orig) circle (\r);
\draw[dashed,thick] (orig) ellipse (\r{} and \r/3);
% Axes
\draw[->] (orig) -- ++(-\r/5,-\r/3) node[below] (x1) {$x$};
\draw[->] (orig) -- ++(\r,0) node[right] (x2) {$y$};
\draw[->] (orig) -- ++(0,\r) node[above] (x3) {$z$};
%Angles
\pic [draw=gray,text=gray,->,"$\phi$"] {angle = x1--orig--phi};
\pic [draw=gray,text=gray,<-,"$\theta$",angle eccentricity=1.4] {angle = a--orig--x3};
\end{tikzpicture}
\end{document}
问 tikz绘图调用库函数编译报错