0

I'm trying to draw a directed graph where each vertex and each arrow can be colored individually by a specific color. I have a code that mostly works:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta,decorations.markings}
\begin{document}

\begin{tikzpicture}[
       decoration = {markings,mark=at position .5 with {\arrow{Stealth[length=2mm]}}},
       Bullet/.style = {circle, fill=#1,label=#1,draw=black!80, line width=0.2mm,
       inner sep=2.4pt, node contents={},},
every edge/.style = {draw, postaction=decorate}
                        ]
%
\node (a) at (0,2) [Bullet=red, label=below left:$a$];
\node (b) at (2,4) [Bullet=MidnightBlue, label=above:$b$];
%
\path  
(a) edge [Plum] (b) ;
\end{tikzpicture}
\end{document}

The problem is that when compiled (using Overleaf) it produces almost what I want, except for also printing the names of the colors of the nodes (vertices) on top of the nodes:

Image

What am I doing wrong that produces this result? How can I remove the color names? Thank you for reading!


For an explanation of the decoration settings, I want the edges to have an arrowhead in the middle (as in the image), and I also want a black outline on the nodes (vertices) which is what I attempted to write in this section as well.

4

1 Answer 1

1

As @SandyG already told in a comment, you are using the color name twice in your Bullet/.style once as fill=#1 and second as label=#1. The fill=#1 sets the fill color. The label=#1 outputs the color name as label. So removing the label=#1, solves your issue:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta,decorations.markings}
\begin{document}

\begin{tikzpicture}[
       decoration = {markings,mark=at position .5 with {\arrow{Stealth[length=2mm]}}},
       Bullet/.style = {circle, fill=#1,draw=black!80, line width=0.2mm,
       inner sep=2.4pt, node contents={},},
every edge/.style = {draw, postaction=decorate}
                        ]
%
\node (a) at (0,2) [Bullet=red, label=below left:$a$];
\node (b) at (2,4) [Bullet=MidnightBlue, label=above:$b$];
%
\path  
(a) edge [Plum] (b) ;
\end{tikzpicture}
\end{document}

enter image description here

1
  • @SandyG I've made this answer instead of asking you to convert your comment into an answer, because there already have been 4 close votes. If you'd like to answer yourself, please do so and I'll vote to delete this one.
    – cabohah
    Commented Apr 25 at 8:11

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