0

so I have been trying to solve for a long time and after a lot of googling I couldn't find the problem (LaTeX noob). I'm basically trying to draw the following (the one from @Bernard): Drawing Dijkstra algorithm on a graph without adding it as a image?

and I'm getting the following error:

LaTeX Error: Option clash for package xcolor.
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.21 

The package xcolor has already been loaded with options:
  []
There has now been an attempt to load it with options
  [dvipsnames,table,xcdraw]
Adding the global options:
  ,dvipsnames,table,xcdraw
to your \documentclass declaration may fix this.
Try typing  <return>  to proceed.
Line 21: 
\usepackage[dvipsnames,table,xcdraw]{xcolor}

Package xcolor Error: Undefined color `Gainsboro'.
See the xcolor package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.270 ...lstyle = solid, fillcolor = Gainsboro!60}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

Line 270: 
$ \psset{mnode=Circle, radius = 0.25cm}\psset{fillstyle = solid, fillcolor = Gainsboro!60}

This is the part of my code where the problem is happening:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{textcomp}
\usepackage{dsfont}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{hhline}
\usepackage{fancyvrb}
\setlength{\parindent}{4em}
\usepackage{tikz}
\usepackage{array,multirow,graphics}
\usepackage[normalem]{ulem}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} 
\usepackage[T1]{fontenc}
\usepackage{colortbl}
\usepackage[dvipsnames,table,xcdraw]{xcolor}

\title{FUN- Assignment2}
\author{Abdul Malek Altawekji, 1221601}
\date{December 2017}

\begin{document}

\maketitle


\textbf{Exercise 6)}

\psset{arrowinset=0.12, arrows =->, shortput = nab}
$ \psset{mnode=Circle, radius = 0.25cm}\psset{fillstyle = solid, fillcolor =       
 Gainsboro!60}
\def\pscolhooki{\psset{fillstyle = solid, fillcolor = SteelBlue}}
\begin{psmatrix}[colsep=1.5cm, rowsep = 1cm]
& [name = t] 2 & [name = v] ∞ \\
[name = s]\textcolor{white}{0} & & & [name = x] ∞ \\
& [name = u]8 & [name = w]∞
%%% labels and arrows
\psset{labelsep = 2pt}
\foreach \T/\W in {v/6,w/3,u/5}{\ncline{t}{\T}\naput{\W}}
\ncline{v}{x}²
\ncline{w}{x}₇
\ncline{w}{u}₁
%%
\psset{fillstyle = none, arcangle = -20}
{\psset{border = 2pt, bordercolor = Gainsboro}
  \ncarc{s}{t}₂
  \ncarc{s}{u}₈}
\ncarc{u}{s}⁸
\ncarc[nodesep= 0pt]{v}{w}\nbput{5}
\ncarc{w}{v}\nbput{4}
\ncarc[arcangle = -65]{v}{s}\nbput[npos = 0.7]{1}
% \nccurve{linecolor = red}{v}{s}
\psset{labelsep = 1em}
\foreach \L in {s, t, u}{\uput[l](\L){\L\strut}}
\foreach \L in {v, w, x}{\uput[r](\L){\L}}
  \end{psmatrix} $

   \end{document}
3

as supplement to Heiko Oberdiek answer:

  • you not need to load graphics, it is already load by graphicx package
  • with \usepackage[dvipsnames,table,xcdraw]{xcolor} you not need to load colortbl
  • in image you use color Gainsboro which is defined with svgnames
  • why you load tikz package if you not use it?

considering comments above, your example become:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{textcomp}
\usepackage{dsfont}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{hhline}
\usepackage{fancyvrb}
\setlength{\parindent}{4em}
\usepackage[dvipsnames,svgnames,xcdraw, table]{xcolor}
%\usepackage{tikz}
\usepackage{array,multirow,%graphics
            }
\usepackage[normalem]{ulem}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}
%\usepackage{colortbl}

\title{FUN- Assignment2}
\author{Abdul Malek Altawekji, 1221601}
\date{December 2017}

\begin{document}

\maketitle
\textbf{Exercise 6)}

\psset{arrowinset=0.12, arrows =->, shortput = nab}
$ \psset{mnode=Circle, radius = 0.25cm}\psset{fillstyle = solid, fillcolor =
 Gainsboro!60}
\def\pscolhooki{\psset{fillstyle = solid, fillcolor = SteelBlue}}
\begin{psmatrix}[colsep=1.5cm, rowsep = 1cm]
& [name = t] 2 & [name = v] ∞ \\
[name = s]\textcolor{white}{0} & & & [name = x] ∞ \\
& [name = u]8 & [name = w]∞
%%% labels and arrows
\psset{labelsep = 2pt}
\foreach \T/\W in {v/6,w/3,u/5}{\ncline{t}{\T}\naput{\W}}
\ncline{v}{x}²
\ncline{w}{x}₇
\ncline{w}{u}₁
%%
\psset{fillstyle = none, arcangle = -20}
{\psset{border = 2pt, bordercolor = Gainsboro}
  \ncarc{s}{t}₂
  \ncarc{s}{u}₈}
\ncarc{u}{s}⁸
\ncarc[nodesep= 0pt]{v}{w}\nbput{5}
\ncarc{w}{v}\nbput{4}
\ncarc[arcangle = -65]{v}{s}\nbput[npos = 0.7]{1}
% \nccurve{linecolor = red}{v}{s}
\psset{labelsep = 1em}
\foreach \L in {s, t, u}{\uput[l](\L){\L\strut}}
\foreach \L in {v, w, x}{\uput[r](\L){\L}}
  \end{psmatrix} $

\end{document}

and gives:

enter image description here

however, considering my answer to your question, you will cut compilation time to about 1/4. with some adoption of answer to your mwe:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{fancyvrb}
\setlength{\parindent}{4em}

\usepackage{amsmath,amssymb,amsthm}
\usepackage{textcomp}
\usepackage{dsfont}

\usepackage{graphicx}
\usepackage[dvipsnames,svgnames,xcdraw, table]{xcolor}
\usepackage{array, hhline, multirow}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, positioning, quotes}

 \usepackage[normalem]{ulem}

\title{FUN- Assignment2}
\author{Abdul Malek Altawekji, 1221601}
\date{December 2017}

\begin{document}
\maketitle
\textbf{Exercise 6)}
    \begin{center}
    \begin{tikzpicture}[
node distance = 22mm and 24mm,
every state/.append style = {inner sep=0pt, fill=gray!10,
                             minimum size=7mm},
every edge/.style = {draw, -Triangle, bend angle=15},
                auto=right,
                        ]
    \clip   (-0.4,-3.1) rectangle + (9.7,7.7);%%% <--- added for removing spurious white space above image
\node (s1) [state,fill=gray!50]         {0};
\node (s2) [state, above right=of s1]   {2};
\node (s3) [state, right=of s2]         {$\infty$};
\node (s4) [state, below right=of s3]   {$\infty$};
\node (s5) [state, below  left=of s4]   {$\infty$};
\node (s6) [state, left=of s5]          {8};
%
\draw[gray!30, line width=5pt]
        (s1) to                     (s2)
        (s1) to [bend right=15]     (s6);

%
\draw   (s1) edge ["2"]             (s2)
        (s1) edge [bend right,"8"]  (s6)
        (s2) edge ["6"]             (s3)
        (s2) edge ["3"]             (s5)
        (s2) edge ["5"]             (s6)
        (s3) edge [out=135, in=90,looseness=1.5, "1"]  (s1)
        (s3) edge ["2"]             (s4)
        (s3) edge [bend right,"5"]  (s5)
        (s5) edge [bend right,"4"]  (s3)
        (s5) edge ["7"]             (s4)
        (s5) edge ["1"]             (s6)
        (s6) edge [bend right,"8"]  (s1);
\end{tikzpicture}
    \end{center}
\end{document}

you will obtain:

enter image description here

if you like to have different (more colorful) coloring of state nodes, it is simple replace used gray colors used in state definition and use with desired ones.

  • Thanks a lot! i indeed use other packages but for the rest of the file which i didn't copy here – Does it matter Dec 7 '17 at 14:51
3

Package xcolor was already loaded by package tikz without options. LaTeX allows several \usepackage statements for the same package, but it does load the package only once (the first time). Less options in further \usepackage commands are no problem. But LaTeX complains, if it sees new options as in this case.

Solution:

Just load xcolor before tikz:

\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{tikz}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.