在 Latex 中使用 tikzpicture 时无法识别的命令

在 Latex 中使用 tikzpicture 时无法识别的命令

编译金字塔图形时弹出无法识别的命令?是什么原因?如何解决?

请参阅下面的图片:

\begin{figure}[!h]
    \centering
\tikzset{tri/.style={%
                        regular polygon,
                        regular polygon sides=3, %% For fun, vary this number at will
                        minimum size=#1,
                        draw,
                        thick,
                        anchor=north
                    },
                    ptext/.style={font=\bfseries,align=center,text width=0.8*\pyrsize}
        }

    \NewDocumentCommand{\pyramid}{sO{}mm}{% #3 size; #4 entries
    \begin{tikzpicture}
        \pgfmathsetmacro{\incrrate}{0.80}% The rate at which the triangles decrease in size
        \coordinate (T) at (0,0);
        \foreach \test/\testi [count=\testnum from 1] in {#4}{\xdef\tot{\testnum}}%
        \pgfmathsetmacro{\incr}{#3/\tot}
        \foreach \step/\col [count=\stepnum from 0] in {#4}{%
            \pgfmathsetlengthmacro{\pyrsize}{#3-\incrrate*\stepnum*\incr}
            \node[tri=\pyrsize,fill=\col] (T\stepnum) at (T) {};
            \ifnum\stepnum=\numexpr\tot-1\relax
            \pgfmathsetlengthmacro{\lift}{0.0*\incr*\incrrate}% raise text in top shape
            \else
            \pgfmathsetlengthmacro{\lift}{0.1*\incr*\incrrate}% raise text in remaining shapes
            \fi
            \node[above=\lift of T\stepnum.south,ptext] {\step\strut};
        }%
    \end{tikzpicture}%
}
    
    \pyramid{3.0in}{Inner control/green, Primery Control/olive, Secondary control/yellow, Tertiary\\control/orange}

\end{figure}

在此处输入图片描述

相关内容