2

I want to draw a graph exactly like the output of the following answer, but with vertices of different colors and different labels.

https://tex.stackexchange.com/a/357243/148579

What parameters should be added to the latex code for having vertices with different colors and different labels? Because all the vertices of the graph in the above answer have the same color (black) and the same label (u) (without considering indexes).

2
  • @Qrrbrbirlbel , Thank you, just I added something else to my question, as the labels should also be different in each vertex. Meanwhile, what you said changes the edge color not vertices color.
    – Questioner
    Commented Aug 12, 2022 at 12:49
  • Well, it depens. Is there a rule on how to color or label them? You can add this information in the loop like so \foreach \angle/\lab/\col[count=\n] in {120/v/red, …} {\node[roundnode, color=\co, label=\angle:{$\lab_{\ni}$}] … {}; You can prepare different styles that are applied automatically in the loop. Commented Aug 12, 2022 at 13:11

1 Answer 1

2

You could add color and label variables to your for loop:

enter image description here

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning, fit}

\begin{document}
\begin{tikzpicture}[roundnode/.style={circle, fill=#1, inner sep=0pt, minimum size=4mm}]

    \foreach \i/\col/\lab [count=\ni] in {120/red/A, 60/orange/B, 0/yellow/C, -60/green/D, -120/blue/E, -180/violet/F}
        \node[roundnode=\col, label=\i:{\lab}] at (\i:2cm) (u\ni) {};

            %Lines
            \draw[->] (u2) -- (u5);
            \draw[->] (u2) -- (u6);
            \draw[->] (u3) -- (u5);
            \draw[->] (u3) -- (u6);
            \draw[->] (u4) -- (u5);
            \draw[->] (u4) -- (u6); 
          \end{tikzpicture}
\end{document}
2
  • Is there a way to use (x,y) coordinate rather than angle to determine the position of the vertices? (If I should ask this as a separate question, just let me know.)
    – Questioner
    Commented Aug 12, 2022 at 16:50
  • Quation is here: tex.stackexchange.com/q/653853/148579
    – Questioner
    Commented Aug 12, 2022 at 16:59

You must log in to answer this question.

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