如何将颜色作为参数传递

如何将颜色作为参数传递

在解释我的问题之前,如果这是一个重复的问题,我很抱歉,但我无法找到一个与我的问题相同的回答/问题。

为了创建图表,我定义了自己的函数,该函数以先前定义的点为中心绘制一个矩形,并按一定角度旋转,该角度也作为参数传递。代码:

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}

\documentclass[tikz,border=2mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,automata,positioning,arrows}
\usetikzlibrary{patterns}
\usepackage{xcolor}

\newdimen\XCoord
\newdimen\YCoord

\newcommand*{\ExtractCoordinate}[1]{
    \path (#1); \pgfgetlastxy{\XCoord}{\YCoord};
}

\newcommand{\myrec}[5]{% #1: center, #2: horizontal edge, #3: vertical edge, #4 angle of rotation, #5: edge color
    \ExtractCoordinate{$(#1)$};
    \node (a) at (\XCoord,\YCoord) {};
    \draw [solid,rotate=#4,draw=#5] let \p1=(a) in ($ (\x1,\y1) + 0.5*(-#2,#3) $) rectangle ($ (\x1,\y1) + 0.5*(#2,-#3) $);
}

\begin{document}
    \begin{tikzpicture}
        \node (Point) at (2,3) {Point};
        \myrec{$(Point)$}{1.5}{2.2}{0}{blue};
    \end{tikzpicture}
\end{document}

现在,我尝试改进此功能,增加选择边缘颜色的可能性。但是,尽管我以适合大多数人的方式进行了操作,但我还是收到错误:Package xcolor Error: Undefined color ';'。关于如何正确将颜色作为参数传递,您有什么想法吗?

编辑:

我还不明白为什么,但重新启动计算机就可以解决问题。

相关内容