14

I would like to mark my nodes in a graph without using colors because it will be printed in black and white. For example by drawing a vertical line in the first vertex, a horizontal line in the second, two lines in the third,... . Or if there is a better way to do this, I would like to here it.

Thank you for your time.

\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}
2
  • @user748790: Well, that really depends on what you're trying to show with the colours. In your example, the colours don't seem to be adding any new information (no grouping or pattern, for example), since each node has a unique colour. That's something that's very difficult to do in black and white without looking incredibly noisy. Maybe it's not even necessary to add a distinguishing feature to each node, since the reader can tell they're different from their labels?
    – Jake
    Apr 5, 2012 at 21:12
  • @Jake I am trying to demonstrate the Kruskall algoritm step by step. Because the algorithm uses different sets of vertices, I would like to give each set of vertices the same color/mark.
    – Bibtex
    Apr 5, 2012 at 21:16

3 Answers 3

12

Instead of patterns, I would recommend that you use a combination of different shadings, and line styles (thin, thick, ultra thick, or even draw=none) to distinguish the nodes. You can also adjust the text color (as suggested by @Jake), and use dotted or dashed lines (a few of which are probably to be avoided):

enter image description here

\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}
4
  • Yay, this answer begs for a touch of patterns too. :)
    – percusse
    Apr 5, 2012 at 21:22
  • And white text on dark background!
    – Jake
    Apr 5, 2012 at 21:24
  • I think it would be cleaner if it was possible to use some sort of pattern inside the vertices. Is this possible?
    – Bibtex
    Apr 5, 2012 at 21:29
  • @Bibtex: Meant to mention that I did not think patterns were a good idea, but I think you can see that from the other answers now. Apr 6, 2012 at 0:27
10

Here's another possibility using the patterns library. However, as Jake mentioned in his comment, this can turn out to be incredibly noisy. I slightly modified some of the patterns defined in pgflibrarypatterns.code.tex in an attempt to reduce the noise by reducing the pattern opacity and increasing the distance between the lines (but still this example still seems to be "too crowded"):

\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}

enter image description here

0
8

OK, This can get uglier look as it can, but these have colors.

\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} 

enter image description here

1
  • You can also use text=red as node option instead of \textcolor
    – Tobi
    Apr 5, 2012 at 23:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .