0

I would like to generate the attached graph by latex. It is also a hyperedges graph. Could you help me, please? The colours may be skipped.

Thanks in advance.

enter image description here

1
  • Welcome to TeX.SE! What you try so far?
    – Zarko
    Jul 30, 2019 at 14:05

2 Answers 2

3

You should provide a MWE! Anyway, below is my code.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[line width=1.2pt,
n/.style={circle,draw=#1,text=#1,font=\bfseries\sffamily},
arr/.style={-latex,shorten >=1pt,#1}]

\path
(0,0)       node[n=black] (L1) {2} 
+(0:1)      node[n=black] (R1) {1}
++(-90:1.5) node[n=blue] (L2) {1} 
+(0:1)      node[n=blue] (R2) {2}
++(-90:1.5) node[n=red!70!black] (L3) {2} 
+(0:1)      node[n=red!70!black] (R3) {1};

\draw[arr] (L1)--(L2) coordinate[pos=.4](A);
\fill (A) circle(1mm) node[left=1mm]{$X_2$};
\draw[arr] (R1)--(R2) coordinate[pos=.4](B);
\draw[arr] (B)--(L2);
\fill (B) circle(1mm) node[right=1mm]{$X$};

\draw[arr=blue] (L2)--(L3) coordinate[pos=.4] (C);
\fill[blue] (C) circle(1mm) node[left=1mm]{$R_1$};
\draw[arr=blue] (R2)--(R3) coordinate[pos=.4](D);
\draw[arr=blue] (D)--(L3);
\draw[arr=blue] (C)--(R2);
\fill[blue] (D) circle(1mm) node[right=1mm]{$R_2$};

\draw[arr] (L3)--+(-90:.8);
\draw[arr] (R3)--+(-90:.8);
\end{tikzpicture}
\end{document}
3
  • Why OP should provide a MWE if he got answer anyway :-)
    – Zarko
    Jul 30, 2019 at 14:40
  • @Zarko OP is very new to texSE. I hope in next question he does know and include a MWE.
    – Black Mild
    Jul 30, 2019 at 14:45
  • @Sultan Alam, I am right ?
    – Black Mild
    Jul 30, 2019 at 14:45
2

An exercise, using @Black Mild answer as OP's MWE:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 12mm and 9mm,
  start chain = A going below,
   dot/.style = {circle, fill=#1, inner sep=2pt, outer sep=0pt},
    cn/.style = {circle, draw=#1, semithick,
                 text=#1, minimum size=1.2em, inner sep=2pt,
                 on chain=A},
every edge/.style = {draw=#1, -{Triangle[angle=60:2pt 3]},semithick, shorten >=1pt}
                        ]
\node[cn=black] {2};                % A-1
\node[cn=blue]  {1};
\node[cn=red!70!black]  {2};        % A-3
%
\draw   (A-1) edge[black] node (d1) [dot=black,label=left:$X_2$] {} (A-2)
        (A-2) edge[blue]  node (d2) [dot=blue, label=left:$R_1$] {} (A-3) 
        (A-3) edge[black] ++ (0,-1)
        ;
%%        
\node[cn=black,
      right=of A-1] {1};            % A-4
\node[cn=blue]      {2};
\node[cn=red!70!black]  {1};        % A-6
%
\draw   (A-4) edge[black] node (d3) [dot=black,label=right:$X_1$] {} (A-5)
        (A-5) edge[blue]  node (d4) [dot=blue, label=right:$R_2$] {} (A-6)
        (A-6) edge[black] ++ (0,-1);
%% cross lines
\draw   (d3) edge (A-2)
        (d2) edge (A-5)
        (d4) edge (A-3);
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    Which one is cleaner or more elegant, Zarko ?
    – Black Mild
    Jul 30, 2019 at 18:46
  • 1
    @BlackMild, result or code? Matter of taste :-). As I wrote, I made (in my spar time) just an exercise ;-)
    – Zarko
    Jul 30, 2019 at 19:53

You must log in to answer this question.

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