以下是 MWE(以下代码取自这里(略有修改):
\documentclass[tikz]{standalone}
\tikzset{
use bounding box relative coordinates/.style={
shift={(current bounding box.south west)},
x={(current bounding box.south east)},
y={(current bounding box.north west)}
},
label/.style={draw=golden-rod},
}
\begin{tikzpicture}
\node[use as bounding box] {\includegraphics{example-image-a}};
\begin{scope}[use bounding box relative coordinates]
\node[label][golden-rod] (Label) at (0.3,0.3) {GR};
\draw[golden-rod] (Label.west) edge[-stealth] (0.1,0.35)
(Label.west) edge[-stealth] (0.1,0.25);
\end{scope}
\end{tikzpicture}
\end{document}
我面临的问题是我无法使用颜色黄花可从xcolor
包中获得。当我运行上述代码时,出现以下错误:
- 程序包 pgf 错误:未知箭头类型‘golden’
- 程序包 pgf 错误:未知箭头类型‘rod’
- 程序包 xcolor 错误:未定义颜色“golden-rod”
当我将“golden-rod”更改为“Goldenrod”时,出现以下错误:
- 软件包 pgf 错误:我不知道密钥“/tikz/Goldenrod”,我将忽略它。也许你拼错了。
- 包 xcolor 错误:未定义颜色“Goldenrod”。
一般来说,我无法使用名称由两部分组成的颜色。有办法解决这个问题吗?
答案1
除了拼写错误(golden-rod
不是正确的Goldenrod
)之外,还有两个问题必须解决才能使代码可编译。
首先,您应该确定color=Goldenrod
您是否想要金黄色的框边框和文本,或者draw=Goldenrow
是否想要金黄色框内的黑色文本。
(这解决了Package pgf Error: I do not know the key '/tikz/Goldenrod' and I am going to ignore it. Perhaps you misspelled it.
)
其次,只有在使用选项goldenrod
加载时才会定义颜色。由于您 内部也会加载,因此您不能使用。相反,我建议使用。xcolor
svgnames
tikz
xcolor
\documentclass[tikz]{standalone}\usepackage[svgnames]{xcolor}
\PassOptionsToPackage{svgnames}{xcolor} \documentclass[tikz]{standalone}
(这解决了Package xcolor Error: Undefined color 'Goldenrod'.
:)
完整且可编译的 MWE 如下所示:
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[tikz]{standalone}
\tikzset{
use bounding box relative coordinates/.style={
shift={(current bounding box.south west)},
x={(current bounding box.south east)},
y={(current bounding box.north west)}
},
label/.style={draw=Goldenrod},
}
\begin{document}
\begin{tikzpicture}
\node[use as bounding box] {\includegraphics{example-image-a}};
\begin{scope}[use bounding box relative coordinates]
\node[label][color=Goldenrod] (Label) at (0.3,0.3) {GR};
\draw[Goldenrod] (Label.west) edge[-stealth] (0.1,0.35)
(Label.west) edge[-stealth] (0.1,0.25);
\end{scope}
\end{tikzpicture}
\end{document}