![如何用图案标记图中的节点](https://linux22.com/image/248051/%E5%A6%82%E4%BD%95%E7%94%A8%E5%9B%BE%E6%A1%88%E6%A0%87%E8%AE%B0%E5%9B%BE%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9.png)
我想在不使用颜色的情况下在图形中标记我的节点,因为它将以黑白打印。例如,在第一个顶点画一条垂直线,在第二个顶点画一条水平线,在第三个顶点画两条线……。或者如果有更好的方法可以做到这一点,我想在这里分享。
感谢您的时间。
\documentclass[a4paper,11pt,titlepage]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{figure*}[h!]
\centering
\begin{tikzpicture}[node distance=1.5cm,>=stealth',bend angle=45,auto]
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,fill=red!20,inner sep=0.05cm] (1) {$v_{1}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,fill=green!20,inner sep=0.05cm, below of=1, xshift=2cm] (2) {$v_{2}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,fill=cyan!20,inner sep=0.05cm,right of=2, xshift=1cm] (3) {$v_{3}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,fill=purple!30,inner sep=0.05cm,below of=2, xshift=1.5cm] (5) {$v_{5}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,fill=red!20,inner sep=0.05cm,below of=2, xshift=-2cm] (4) {$v_{4}$};
\end{tikzpicture}
\end{figure*}
\end{document}
答案1
我建议您使用不同阴影和线条样式(thin
、thick
、ultra thick
甚至draw=none
)的组合来区分节点,而不是使用图案。您还可以调整文本颜色(如 @Jake 所建议的),并使用虚线或虚线(其中一些可能应避免使用):
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\tikzset{every node/.append style={minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,inner sep=0.05cm}}%
\begin{document}
\begin{tikzpicture}
\node[fill=gray!5, thin ] (1a) {$u_{1}$};
\node[fill=gray!10, right of=1a, thick ] (2a) {$u_{2}$};
\node[fill=gray!30, right of=2a, thin ] (3a) {$u_{3}$};
\node[fill=gray!60, right of=3a, thick ] (4a) {$u_{4}$};
\node[fill=gray!30, right of=4a, draw=none] (5a) {$u_{5}$};
\node[fill=black!10, below of=1a, thin ,text=white] (1b) {$v_{1}$};
\node[fill=black!10, right of=1b, thick ,text=white] (2b) {$v_{2}$};
\node[fill=black!30, right of=2b, thin ,text=white] (3b) {$v_{3}$};
\node[fill=black!60, right of=3b, thick ,text=white] (4b) {$v_{4}$};
\node[fill=black!30, right of=4b, draw=none,text=white] (5b) {$v_{5}$};
\node[fill=black!10, below of=1b, thin ,text=gray] (1c) {$x_{1}$};
\node[fill=black!10, right of=1c, thick ,text=gray] (2c) {$x_{2}$};
\node[fill=black!30, right of=2c, thin ,text=gray] (3c) {$x_{3}$};
\node[fill=black!60, right of=3c, thick ,text=gray] (4c) {$x_{4}$};
\node[fill=black!30, right of=4c, draw=none,text=gray] (5c) {$x_{5}$};
\node[fill=black!10, below of=1c, thin ,dashed] (1d) {$y_{1}$};
\node[fill=black!10, right of=1d, thick ,dashed] (2d) {$y_{2}$};
\node[fill=black!30, right of=2d, thin ,dashed] (3d) {$y_{3}$};
\node[fill=black!60, right of=3d, thick ,dashed] (4d) {$y_{4}$};
\node[fill=black!30, right of=4d, draw=none,dashed] (5d) {$y_{5}$};
\node[fill=black!10, below of=1d, thin ,dotted] (1e) {$z_{1}$};
\node[fill=black!10, right of=1e, thick ,dotted] (2e) {$z_{2}$};
\node[fill=black!30, right of=2e, thin ,dotted] (3e) {$z_{3}$};
\node[fill=black!60, right of=3e, thick ,dotted] (4e) {$z_{4}$};
\node[fill=black!30, right of=4e, draw=none,dotted] (5e) {$z_{5}$};
\end{tikzpicture}
\end{document}
答案2
这是使用模式库的另一种可能性。然而,杰克在他的评论中提到,这可能会变得非常嘈杂。我稍微修改了定义的一些图案,pgflibrarypatterns.code.tex
试图通过降低图案不透明度和增加线条之间的距离来减少噪音(但这个例子仍然似乎“太拥挤”):
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,patterns}
\pgfdeclarepatternformonly{soft horizontal lines}{\pgfpointorigin}{\pgfqpoint{100pt}{1pt}}{\pgfqpoint{100pt}{3pt}}%
{
\pgfsetstrokeopacity{0.3}
\pgfsetlinewidth{0.1pt}
\pgfpathmoveto{\pgfqpoint{0pt}{0.5pt}}
\pgfpathlineto{\pgfqpoint{100pt}{0.5pt}}
\pgfusepath{stroke}
}
\pgfdeclarepatternformonly{soft crosshatch}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{4pt}{4pt}}{\pgfqpoint{3pt}{3pt}}%
{
\pgfsetstrokeopacity{0.3}
\pgfsetlinewidth{0.4pt}
\pgfpathmoveto{\pgfqpoint{3.1pt}{0pt}}
\pgfpathlineto{\pgfqpoint{0pt}{3.1pt}}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{3.1pt}{3.1pt}}
\pgfusepath{stroke}
}
\begin{document}
\begin{tikzpicture}[
every node/.style={minimum size=0.5cm, draw,circle,
font={\sffamily\Large\bfseries},inner sep=0.05cm},
node distance=1.5cm,>=stealth',bend angle=45,auto]
\node[pattern=soft horizontal lines] (1) {$v_{1}$};
\node[fill=gray!10, below of=1, xshift=2cm] (2) {$v_{2}$};
\node[pattern=dots,right of=2, xshift=1cm] (3) {$v_{3}$};
\node[below of=2, xshift=-2cm] (4) {$v_{4}$};
\node[pattern=soft crosshatch,below of=2, xshift=1.5cm] (5) {$v_{5}$};
\end{tikzpicture}
\end{document}
答案3
好吧,这可能会变得更丑,但它们有颜色。
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,patterns}
\begin{document}
\begin{tikzpicture}[node distance=1.5cm,>=stealth',bend angle=45,auto]
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,fill=brown!90,inner sep=0.05cm,draw=none] (1) {\textcolor{white}{$v_{1}$}};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,pattern=fivepointed stars,pattern color=green,inner sep=0.05cm, below of=1, xshift=2cm, thick] (2) {\textcolor{red}{$v_{2}$}};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,pattern=dots,pattern color=blue,inner sep=0.05cm,right of=2, xshift=1cm, thin] (3) {\textcolor{pink}{$v_{3}$}};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,pattern=bricks,pattern color=red,inner sep=0.05cm,below of=2, xshift=1.5cm, thin] (4) {$v_{4}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,inner sep=0.05cm,below of=2, xshift=-2cm, very thin,pattern=crosshatch dots,pattern color=red] (5) {$v_{5}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,inner sep=0.05cm,right of=2, xshift=1cm, yshift=1.5cm,very thin,pattern=north east lines,pattern color=blue!40] (6) {$v_{6}$};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,inner sep=0.05cm,below of=1, xshift=-1.5cm, very thin,shading=true,inner color=white,outer color=blue!40] (7) {\textcolor{magenta}{$v_{7}$}};
\node[minimum size=0.5cm, draw,circle,font=\sffamily\Large\bfseries,inner sep=0.05cm,above of=1, xshift=-1.5cm, very thin,shading=true,left color=green,right color=blue!40,text=red] (8) {$v_{8}$};
\end{tikzpicture}
\end{document}