1

I was unable to create a complete graph on 5 vertices with edges coloured red and blue in Latex. The picture of such graph is below. I would be very grateful for help!

enter image description here

2
  • 2
    Welcome to TeX-SX! As a new member, it is recommended to visit the Welcome and the Tour pages to be informed about our format and also to know about Minimal Example. Otherwise, more specifically about your question: You should clarify your question with the packages you want to use ( tikz, pstrick, ...) and give a minimal example showing your previous attempts.
    – R. N
    Dec 31, 2020 at 11:28
  • 1
    It is possible to create your drawing yourself with a tool tikzit.github.io
    – Sebastiano
    Dec 31, 2020 at 12:17

4 Answers 4

9
  • Use polar coordinates (angle:distance). For a pentagon, the angles differ by 360/5 = 72 degrees. Since one node is supposed to be at angle 90 (north), the angles are computed from there as 18, 90, 162, 234, and 306 degrees.
  • Lookup the \foreach loop as well as the \draw and \node commands in the TikZ manual.

enter image description here

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\newcommand\size{1}% distance of nodes from center
\begin{tikzpicture}
  \draw[thick,red]  (18:\size) \foreach \a in {90,162,234,306} { -- (\a:\size) } -- cycle;
  \draw[thick,blue] (18:\size) \foreach \a in {162,306,90,234} { -- (\a:\size) } -- cycle;
  \foreach \a in {18,90,162,234,306} { \node[black,fill=black,circle,inner sep=2pt] at (\a:\size){}; }
\end{tikzpicture}
\end{document}
7

Very easy using MetaPost:

\documentclass{standalone}
\usepackage[latex,shellescape]{gmp}
\begin{document}
\begin{mpost}[name=nice]
numeric u; u := 3cm;
for i = 1 upto 5:
    for j = 1 upto i:
        if i <> j:
            draw (u*dir (72i+18)) -- (u*dir(72j+18)) withcolor
            if (abs(i-j) = 1) or (abs(i-j) = 4):
                red
            else:
                blue
            fi
            withpen currentpen scaled 4;
        fi
    endfor
endfor
for i = 1 upto 5: drawdot (u*dir (72i+18)) withpen currentpen scaled 20; endfor
\end{mpost}%
\usempost{nice}%
\end{document}

enter image description here

1
  • 2
    Very good and I approved with the stamp. :-)
    – Sebastiano
    Dec 31, 2020 at 17:07
6

An alternative (for exercise), with using of the regular polygon shape and double loop:

\documentclass[tikz, margin=3.141592]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
dot/.style = {circle, fill=black, inner sep=2pt, outer sep=0pt}
                    ]
\node (n)   [regular polygon, 
             regular polygon sides=5, minimum size=22mm,
             draw=red, thick]  {};
\foreach \i in {1,2,...,5} 
{     
    \foreach \j [evaluate=\j as \k using int(\i+\j)] in {2,3}
    {
    \ifnum\k<6
    \draw[thick,blue]   (n.corner \i) -- (n.corner \k);
    \fi
    }
\node [dot] at (n.corner \i) {};
}
    \end{tikzpicture}
\end{document}

enter image description here

5

Graphs can be produced with the graphs library.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{tikzpicture}
\graph [nodes={circle,inner sep=1pt,fill},radius=1.75cm, 
    clockwise, empty nodes,n=5] { 
    subgraph I_n [clique,edge=blue]; 
    subgraph C_n [edge={red,semithick}]; ,
    };
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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