假设我有如下的简单图形。
\documentclass[12pt,a4paper]{article}
\usepackage{tkz-graph}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\SetUpEdge[lw = 1.5pt, color = black, labelcolor = white]
\GraphInit[vstyle=Classic]
\tikzset{VertexStyle/.append style = {minimum size = 8pt, inner sep = 0pt}}
\Vertices[unit=2]{circle}{a,b,c,d,e,f}
% It's easy to change the color of a vertex!
\AddVertexColor{white}{a,d}
\Edges(a,b,c,d,e,f,a)
\end{tikzpicture}
\end{figure}
\end{document}
来自文档,我可以弄清楚如何改变顶点的颜色,就像代码中所做的那样。但是,我想使用仅有的黑色和白色代表几种颜色。例如,我可以有一个用黑色条填充的顶点吗?如果可以,怎么做?这可以表示“蓝色”,而用黑色填充的顶点表示“绿色”,用白色填充的顶点表示“红色”。
答案1
加载patterns
库,并添加pattern=<style>
到 的定义中VertexStyle
,其中<style>
包括,例如 ,horizontal lines
,vertical lines
,north east lines
等north west lines
。
代码
\documentclass[12pt,a4paper]{article}
\usepackage{tkz-graph}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\SetUpEdge[lw = 1.5pt, color = black, labelcolor = white]
\GraphInit[vstyle=Classic]
\tikzset{VertexStyle/.append style = {minimum size = 8pt, inner sep = 0pt, pattern=north east lines}}
\Vertices[unit=2]{circle}{a,b,c,d,e,f}
% It's easy to change the color of a vertex!
\AddVertexColor{white}{a,d}
\Edges(a,b,c,d,e,f,a)
\end{tikzpicture}
\end{figure}
\end{document}