3

I'm trying to change the colors of two of the edges in the basic graph created by the tkz-graph LaTeX code below to red and the other two to blue and I can't seem to find a way to do it... Any help would be greatly appreciated. Thanks.

\documentclass[a4paper,12pt,reqno]{amsart}
\usepackage{amsmath, amssymb, amsthm, verbatim, inputenc, graphicx, bbold, 
float, calc, bm, dsfont, tikz, pgf, mathtools}
\usepackage{tkz-graph}
\GraphInit[vstyle = Normal]
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\graphicspath{ {C:\Users\Tom\Desktop\Tropical\main document} }


\usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,petri,positioning}

\begin{document}
\tikzset{
    LabelStyle/.append style = { rectangle, draw, minimum width = 2em, fill = white, text = black},
    VertexStyle/.append style = { inner sep=5pt,
        font = \Large\bfseries},
    EdgeStyle/.append style = {->} 
}
\begin{figure}[H]
    \begin{tikzpicture}
    \SetGraphUnit{5}
    \Vertex{1}
    \EA(1){2}
    \SO(1){3}
    \EA(3){4}
    \Edge[color=blue](1)(2)
    \Edge[color=blue](3)(1)
    \tikzset{EdgeStyle/.append style = {->, bend left}}
    \Edge[color=red](3)(4)
    \Edge[color=red](4)(3)
    \end{tikzpicture}
    \caption{caption}
    \label{label}
\end{figure}
\end{document}

It would also be fine if I could make them dashed and not dashed edge lines instead of different colors, but I don't know how to do that either.

4
  • 2
    In a minimal document the colours appear fine. Please complete your code to such a document demonstrating the problem. Apr 7, 2017 at 12:31
  • @AndrewSwann, I have completed the code as asked, I still get the graph in black and white.
    – Tom1212
    Apr 7, 2017 at 12:41
  • 2
    Seems to be because of \GraphInit[vstyle = Normal]. Apr 7, 2017 at 12:42
  • @TorbjørnT. Yes, getting rid of that has it working now, thank you!!!
    – Tom1212
    Apr 7, 2017 at 12:46

1 Answer 1

2

The reason your color settings doesn't work appear to be the \GraphInit[vstyle = Normal], removing that and your code works.

You can alternatively add red and blue to your two \tikzset{EdgeStyle/.append style = {...}} declarations. That is, if you have \tikzset{EdgeStyle/.append style={red}}, the following \Edges will be red. Note that append style doesn't overwrite the existing definition of the style, if you do want to replace the existing style use \tikzset{EdgeStyle/.style={...}}.

Finally, a little comment on your preamble. You load several packages several times, albeit implicitly, so it can be cleaned up a bit:

  • tkz-graph loads TikZ, which loads pgf, so the latter two are not needed. TikZ actually also loads graphicx.
  • The amsart class loads amsmath and amsthm, and it loads amsfonts, which in turn loads amssymb. (mathtools also loads amsmath, but it extends it as well, so that can be kept.)

Normally when using the inputenc package, you would specify the encoding of your .tex file in the optional argument, e.g. \usepackage[utf8]{inputenc}.

\documentclass[a4paper,12pt,reqno]{amsart}
\usepackage{
  verbatim,
  inputenc,
  float,
  calc,
  bm,
  mathtools,
  bbold,
  dsfonts
}

\usepackage{tkz-graph}
\GraphInit[vstyle = Normal]
\usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,petri,positioning}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\graphicspath{ {C:\Users\Tom\Desktop\Tropical\main document} }

\begin{document}
\tikzset{
    LabelStyle/.append style = { rectangle, draw, minimum width = 2em, fill = white, text = black},
    VertexStyle/.append style = { inner sep=5pt,
        font = \Large\bfseries},
    EdgeStyle/.append style = {->,blue} % added blue
}
\begin{figure}[H]
    \begin{tikzpicture}
    \SetGraphUnit{5}
    \Vertex{1}
    \EA(1){2}
    \SO(1){3}
    \EA(3){4}
    \Edge[color=blue](1)(2)
    \Edge[color=blue](3)(1)
    \tikzset{EdgeStyle/.append style = {bend left,red}} % added red
    \Edge[color=red](3)(4)
    \Edge[color=red](4)(3)
    \end{tikzpicture}
    \caption{caption}
    \label{label}
\end{figure}
\end{document}

You must log in to answer this question.

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