tikz绘图调用库函数编译报错

发布于 2023-03-30 11:31:20

usetikzlibrary{angles,quotes}%编译报错:
I can't find file 'tikzlibraryangles.code.tex'
请问是什么问题?

查看更多

关注者
0
被浏览
1.2k
3 个回答
寄存器
寄存器 2023-03-30
这家伙很懒,什么也没写!

未提供MWE,无法判断问题,以下这个代码执行没有任何问题:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{angles}


\begin{document}

\tikz \draw (2,0) coordinate (A) -- (0,0) coordinate (B)
            -- (-1,-1) coordinate (C)
            pic [fill=black!50] {angle = A--B--C}
            pic [draw,->,red,thick,angle radius=1cm] {angle = C--B--A};

\end{document}
贾屹峰
贾屹峰 2023-03-30
这家伙很懒,什么也没写!

上面是WME

Sagittarius Rover
我要成为Typst糕手/(ㄒoㄒ)/~~

@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}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览