5

I am a beginner in LaTeX, especially in TikZ package.

I want to draw Peterson graph with some styles.

My code

\documentclass{article}

\usepackage{tikz}
\usepackage{caption}
\usepackage{graphicx}

\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}
\usetikzlibrary[graphs]

\tikzset{   
    every node/.style={draw, circle, very thick},
    mark/.style={fill=black!50, circle},    
}

\begin{document}
    \begin{figure}
        \begin{tikzpicture}[]
            \graph [simple, edges={thick}, clockwise] {
                subgraph C_n [n=5, name=A, radius=2cm]; 
                subgraph I_n [V={a,b,c,d,e}, name=B, radius=1cm];           

                (A 5)[mark] --[red] (A 4)[mark],
                A 1 -- B a,
                A 2 -- B b,
                A 3 -- B c,
                A 4 -- B d,
                A 5 -- B e,
                B a -- B c,
                B a -- B d,
                B b -- B e,
                B b -- B d,
                B e -- B c
            };

        \end{tikzpicture}
    \end{figure}    
\end{document}

I expect, that nodes 4 and 5 will be gray, but I have only red edge.

enter image description here

What did I do wrong?

  • 1
    your code is not compileable ! – AndréC Mar 5 at 20:06
  • \tikzset be before \begin{document}, and \begin{tikzpicture}[] in right place. – Michail Golunyatnikov Mar 5 at 20:08
  • Modify your question by clicking on the edit button. – AndréC Mar 5 at 20:09
  • In my opinion, this is a bug in the graphs.standard library, I tried in vain to apply a style to the graphs in this library. It does not work. Let's wait and see what other TikZ users think about it. – AndréC Mar 5 at 21:42
  • 3
    You can not change the color of existing node. The node (A 5) is created in the subgraph command before you try to apply [mark] to it. Check TikZ 3.0: Colorate a specific node in a subgraph. – Kpym Mar 5 at 22:29
3

I followed the link given by @Kpym in his commentary and adapted the solution given by hftf.

\documentclass[tikz,border=5mm]{standalone}

%\usepackage{tikz}
%\usepackage{caption}
\usepackage{graphicx}

\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}


\tikzset{   
    every node/.style={draw, circle, very thick},
    marko/.style={fill=cyan!50, circle},    
}

\begin{document}
 %   \begin{figure}
        \begin{tikzpicture}[]
            \graph [simple, edges={thick},n=5,radius=2cm, clockwise] {
            1;2;3;4[marko];5[marko];
                subgraph C_n [n=5, name=A, radius=2cm]; 
                subgraph I_n [V={a,b,c,d,e}, name=B, radius=1cm];           

                (A 5) --[blue] (A 4),
                A 1 -- B a,
                A 2 -- B b,
                A 3 -- B c,
                A 4 -- B d,
                A 5 -- B e,
                B a -- B c,
                B a -- B d,
                B b -- B e,
                B b -- B d,
                B e -- B c
            };

        \end{tikzpicture}
%        
%        \tikz
%\graph [nodes={draw, circle}, n=5, radius=1.5cm, clockwise]
%{ 1; 2; 3[fill=gray]; 4; 5; subgraph K_n };
  %  \end{figure}    
\end{document}

screenshot

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.