# Simple Tikz graph with colors [duplicate]

In my LATEX document, I would like to have the following graph:

Is there a way I can put these colors next to the vertices without the vertex numbers disappear? I don't want to use online drawing tools..

## marked as duplicate by user156344, Raaja, Stefan Pinnow, Werner, SebastianoMar 26 at 15:52

• Could you show what you have tried so far? – user156344 Mar 26 at 13:27
• Sure, it is here : – independentvariable Mar 26 at 13:28
• Add it to the question. – user156344 Mar 26 at 13:29
• There is nothing that I tried. Because, I don't know how. I don't need to learn how to color each of the five vertices above. Just coloring one will be enough. – independentvariable Mar 26 at 13:30

Here is a possibility with distinct colors.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[Bullet/.style={circle,draw=gray,ultra thick,minimum width=2em}]
\def\LstColors{{"red","blue","orange","yellow","cyan"}}
\path (0,0) node[Bullet,fill=green!60!black] (v0) {$\mathsf{v}0$};
\foreach \X in {1,...,5}
{\pgfmathsetmacro{\mycolor}{\LstColors[\X-1]}
\draw[ultra thick,draw=gray] (v0) -- (90+72-72*\X:2)
node[Bullet,fill=\mycolor] (v\X){$\mathsf{v}\X$};}
\end{tikzpicture}
\end{document}


Or with also varying text colors (and numbers also sf, as implicitly asked for by Joule V ;-).

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[Bullet/.style={circle,draw=gray,ultra thick,minimum width=2em}]
\def\LstColors{{"red","blue","yellow","orange","cyan"}}
\path (0,0) node[Bullet,fill=green!60!black] (u) {$\mathsf{u}$};
\foreach \X in {1,...,5}
{\pgfmathsetmacro{\mycolor}{\LstColors[\X-1]}
\pgfmathsetmacro{\mytextcolor}{\LstColors[mod(\X,5)]}
\draw[ultra thick,draw=gray] (u) -- (90+72-72*\X:2)
node[Bullet,fill=\mycolor,text=\mytextcolor] (v\X){$\mathsf{v\X}$};}
\end{tikzpicture}
\end{document}


• (+1) Just out of curiousity: why $\mathsf{v}\X$ but not $\mathsf{v\X}$? – user156344 Mar 26 at 13:47
• @JouleV There is no special reason, I just want to get something that looks similar to the the OP's screen shot. – user121799 Mar 26 at 13:49

Like this? I use polar coordinates for the coordinates of the nodes.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[mynode/.style={font=\color{yellow}\sffamily,fill=cyan,circle,inner sep=1pt,minimum size=0.75cm}]
\node[mynode] (u) at (0,0) {$u$};
\node[mynode] (v1) at (90:3) {$v_1$};
\node[mynode] (v2) at (-45:3) {$v_2$};
\node[mynode] (v3) at (10:3) {$v_3$};
\node[mynode] (v4) at (-125:3) {$v_4$};
\node[mynode] (v5) at (165:3) {$v_5$};
\draw[gray,very thick] (u)--(v1) (u)--(v2) (u)--(v3) (u)--(v4) (u)--(v5);
\end{tikzpicture}
\end{document}


If you want to customize more

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[mynode/.style={font=\color{#1}\sffamily,circle,inner sep=1pt,minimum size=0.75cm}]
\node[mynode=yellow,fill=cyan] (u) at (0,0) {$u$};
\node[mynode=yellow,fill=red] (v1) at (0,3) {$v_1$};
\node[mynode=green!50!black,fill=white,draw] (v2) at (-45:3) {$v_2$};
\node[mynode=black,fill=yellow] (v3) at (10:3) {$v_3$};
\node[mynode=yellow,fill=green!50!black] (v4) at (-125:3) {$v_4$};
\node[mynode=white,fill=gray] (v5) at (165:3) {$v_5$};
\draw[gray,very thick] (u)--(v1) (u)--(v2) (u)--(v3) (u)--(v4) (u)--(v5);
\end{tikzpicture}
\end{document}


• Thank you! How can add the distinct colors? – independentvariable Mar 26 at 13:38
• v1 red, v3 yellow, etc – independentvariable Mar 26 at 13:38
• Sorry @aslvl95, you seem to be new to tex.sx, but you should try to show a little bit of initiative. If you google "color node tikz" it will show you... That's literally a third of the words you have to type in order to ask for this in the comments here... – sheß Mar 26 at 13:42