1

I want to draw the diagram given below :

enter image description here

I am able to do this much :

\documentclass[11pt]{scrartcl}
\usepackage{tkz-berge}

\begin{document}
\begin{tikzpicture}[scale=.5] 
\GraphInit[vstyle=Art] 
\SetGraphArtColor{red}{olive} 
\grPetersen[form=1,RA=5,RB=3]%
\end{tikzpicture}
\end{document}

This is I am able to draw:

enter image description here

Question : With the help of above code I am able to draw point , but I want to draw four points in a square form and edges between them, see the diagram above.

  • There's no question in your post. Please only ask (specific) questions about problems you encounter / what doesn't work. – magula Sep 17 '17 at 13:01
  • @ magula I have edited the question – new_born Sep 17 '17 at 13:02
  • Welcome to TeX SX! One document class is enough… – Bernard Sep 17 '17 at 13:21
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Jan 23 '18 at 17:51
7

Check out an alternative approach with Asymptote:

enter image description here

%          qgr.tex
% run as
%
% pdflatex qgr.tex
% asy qgr-*.asy
% pdflatex qgr.tex
%
\documentclass[10pt,a4paper]{article}
\usepackage{lmodern}
\usepackage[inline]{asymptote}
\begin{asydef}
struct QuadGraph{
    pair a,b,c,d;
    pair center;
    guide s;
    real startNo;
    pen linePen, dotPen, idPen;
    void operator init(pair a,pair b,pair c,pair d){
        this.a=a; this.b=b; this.c=c; this.d=d; 
        center=(a+b+c+d)/4;
    }
    void draw(pen p=linePen){
        draw(s,p);
    }
    void dot(pen p=dotPen){
        dot(s,p,UnFill);
    }
    void label(pen p=idPen){
        label("$"+string(startNo)+"$",  a,1.5*unit(a-center),p);
        label("$"+string(startNo+1)+"$",b,1.5*unit(b-center),p);
        label("$"+string(startNo+2)+"$",c,1.5*unit(c-center),p);
        label("$"+string(startNo+3)+"$",d,1.5*unit(d-center),p);
    }

    void operator init(pair center, real side, real startNo
    ,pen linePen=currentpen, pen dotPen=currentpen, pen idPen=currentpen){
        this.center=center;
        this.startNo=startNo;
        this.linePen=linePen;
        this.dotPen=dotPen;
        this.idPen=idPen;
        a=center+( side/2, side/2);
        b=center+(-side/2, side/2);
        c=center+(-side/2,-side/2);
        d=center+( side/2,-side/2);
        s=a--b--c--d--cycle;
    }
}

QuadGraph operator*(transform tr, QuadGraph s){
    s.a=tr*s.a; s.b=tr*s.b; s.c=tr*s.c; s.d=tr*s.d;
    s.s=tr*s.s;
    s.center=tr*s.center;
    return s;
}

void joinOut(QuadGraph u, QuadGraph v, pen p=u.linePen){
    draw(u.b--v.a,p);
} 
void joinIn(QuadGraph u, QuadGraph v, pen p=u.linePen){
    draw(u.c--v.d,p);
} 

struct cycloQuad{
    int n;
    QuadGraph[] s;
    real side, R;
    pen linePen, dotPen, idPen;

    void makeCycle(){
        s=new QuadGraph[]; 
        pair u=(0,R);
        real phi;
        for(int i=0;i<n;++i){
            phi=i*360/n;
            s[i]=rotate(phi)*QuadGraph(u,side,startNo=i*4+1,linePen=linePen,dotPen=dotPen,idPen=idPen);
            s[i].draw();
        }
    }

    void draw(){
        for(int i=0;i<n;++i){
            joinOut(s[i],s[(i+1)%n]);
            joinIn (s[i],s[(i+2)%n]);
        }

        for(int i=0;i<n;++i){
            s[i].dot();
            s[i].label();
        }
    }

    void operator init(int n=5, real side=1, real R=12
    ,pen linePen=currentpen, pen dotPen=currentpen, pen idPen=currentpen
        ){
            assert(n>2 && side>0 && R>0);
            this.n=n; this.side=side; this.R=R;
            this.linePen=linePen;
            this.dotPen=dotPen;
            this.idPen=idPen;
            makeCycle();
            draw();
        }
    } 
\end{asydef}

\begin{document}

\begin{asy}
size(8cm);
cycloQuad(linePen=darkblue+1.2bp,idPen=deepred);
\end{asy}

\begin{asy}
size(9cm);
cycloQuad(n=7,side=1.6,R=17,linePen=orange+1.4bp, idPen=blue,dotPen=red+1bp);
\end{asy}

\end{document}

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.