将角度嵌入 TikZ 图片中的问题

将角度嵌入 TikZ 图片中的问题

我正在尝试使用 TikZ 创建pic包含角度库中的角度pic。我得到的错误是

! TeX capacity exceeded, sorry [grouping levels=255].
<argument> ...kz@pp@name {x1}\endcsname }{center}{
                                                  \pgfsettransform {\csname ...
l.18 ...pic text=$\alpha$] {my angle={x1}{x2}{x3}}
                                                  ; % does not work
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

我一直无法解决这个问题。我该如何在自己的图片中绘制角度?

这是MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}
\begin{document}
    \begin{tikzpicture}
        \tikzset{
            pics/my angle/.style n args={3}{
                code = {
                    \draw (#1) -- (#2) -- (#3);
                    \pic [draw] {angle=#1--#2--#3}; % offending line
                }
            }
        }
        
        \coordinate (x1) at (-1, 0);
        \coordinate (x2) at (0, 0);
        \coordinate (x3) at (-0.5, -0.5);
        \pic[pic text=$\alpha$] {my angle={x1}{x2}{x3}}; % does not work
        
%        \pic [draw] {angle=x1--x2--x3}; % this does draw the angle
    \end{tikzpicture}
\end{document}

答案1

问题是pic 与和 一起angle使用,出于某种原因,它不喜欢嵌套到“正常” 中。但是,您可以使用例如将 pic嵌套在您的pic 中。foreground codebackground codecodeforeground codeanglemy angle

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}
\begin{document}
    \begin{tikzpicture}
        \tikzset{pics/my angle/.style n args={3}{
                setup code  ={},
                background code ={},
                foreground code = {\pic [draw] 
                        {angle=#1--#2--#3}; % no longer offending 
                },
                code = {
                    \draw (#1) -- (#2) -- (#3);
                }
            }
        }
        
        \coordinate (x1) at (-1, 0);
        \coordinate (x2) at (0, 0);
        \coordinate (x3) at (-0.5, -0.5);
        \pic[pic text=$\alpha$] 
        {my angle={x1}{x2}{x3}}; %  works now
        
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容