![将两个包(tkz-graph 和 tikzducks)中的环境合并在一起?](https://linux22.com/image/466186/%E5%B0%86%E4%B8%A4%E4%B8%AA%E5%8C%85%EF%BC%88tkz-graph%20%E5%92%8C%20tikzducks%EF%BC%89%E4%B8%AD%E7%9A%84%E7%8E%AF%E5%A2%83%E5%90%88%E5%B9%B6%E5%9C%A8%E4%B8%80%E8%B5%B7%EF%BC%9F.png)
我使用 tkz-graph 包制作了一个图形,并想使用 tikzducks 包制作图形的顶点。(具体来说,我想用彩色鸭子替换任意图形顶点的点)。这可能吗?
这是我的代码:
\begin{tikzpicture}
\renewcommand*{\VertexLineWidth}{2pt}
\GraphInit[vstyle=Welsh]
\Vertices[unit=3]{circle}{A,B,C,D,E,F,G}
\SetVertexNoLabel
\AddVertexColor{red}{B,F} \AddVertexColor{blue}{E,A}
\AddVertexColor{green}{C,G}\AddVertexColor{yellow}{D}
\Vertex[Node]{D}
\Edges(G,E,F,G,B,D,E,C,D,A,C,B,A)\Edges(B,E)
\end{tikzpicture}
答案1
当然,也许是这样:
\documentclass[border=10pt]{standalone}
\usepackage{tkz-graph}
\usetikzlibrary{ducks}
\newcommand*{\AddVertexDuckColor}[2]{%
\begingroup
\tikzset{VertexStyle/.append style = {duck = {duck/body=#1}}}
\foreach \v in {#2} { \Vertex[Node, NoLabel] {\v} }
\endgroup
}
\begin{document}
\begin{tikzpicture}
\GraphInit[vstyle=Welsh]
\tikzset{
duck/.style={
path picture={
\pic[scale=0.25, xshift=-1cm, yshift=-1cm, #1] {duck};
}
},
VertexStyle/.append style={
draw=none,
fill=none,
minimum size=0.6cm,
duck
}
}
\Vertices[unit=3]{circle}{A,B,C,D,E,F,G}
\SetVertexNoLabel
\AddVertexDuckColor{red}{B,F}
\AddVertexDuckColor{blue}{E,A}
\AddVertexDuckColor{green}{C,G}
\Vertex[Node]{D}
\AddVertexDuckColor{yellow}{D}
\Edges(G,E,F,G,B,D,E,C,D,A,C,B,A)
\Edges(B,E)
\end{tikzpicture}
\end{document}