8

How can I make such a graph using tikz?

enter image description here

I can draw the circled nodes and the arrows, but I can't change their position. (e.g. the one that starts from node 1 and ends at node 3).

Edit: I would prefer straight arrows and not curved ones, just as in the drawing.

5

A more straight forward approach may be using the graph library, (requires LuaLaTeX, though). Here is the code using graph library:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{circular}
\begin{document}
\tikz[>=Stealth]\graph[simple necklace layout, nodes={circle,minimum size=.7cm,draw}, node sep=1cm]{
  1,2,6,4,5,3;
  1->[xshift=1pt,yshift=2pt]3 -> 2, 3 ->[xshift=-1pt,yshift=-2pt]1 -> 2;
  3 -> 5 -> 6 ->[xshift=-1pt,yshift=-2pt] 4 ->[xshift=1pt,yshift=-2pt]5, 5 ->[xshift=-1pt,yshift=2pt] 4 ->[xshift=1pt,yshift=2pt] 6;
};
\end{document}

This outputs:

enter image description here

Another possibility could be using a matrix of nodes as follows:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{matrix,arrows.meta}
\begin{document}
\begin{tikzpicture}[>=Stealth,->,line width=.7pt]
\matrix [matrix of math nodes,
column sep={1.5cm,between origins},
row sep={2.2cm,between origins},
nodes={circle, draw, minimum size=1cm}]
{
& |(1)| 1 &   & |(2)| 2 & \\
&  & |(3)| 3 &  \\
& |(6)| 6 &   & |(5)| 5 & \\
&  & |(4)| 4 &   \\};
\draw (1)--(2);
\draw (3)--(2);
\draw[transform canvas={xshift=2pt,yshift=2pt},shorten <= -1pt] (3)--(1);
\draw[transform canvas={xshift=-2pt,yshift=-2pt},shorten <= -1pt] (1)--(3);
\draw (3) -- (5);
\draw (5) -- (6);
\draw[transform canvas={xshift=2pt,yshift=-2pt},shorten >= -1pt] (4) -- (5);
\draw[transform canvas={xshift=-2pt,yshift=2pt},shorten >= -1pt] (5) -- (4);
\draw[transform canvas={xshift=2pt,yshift=2pt},shorten <= -1pt] (4) -- (6);
\draw[transform canvas={xshift=-2pt,yshift=-2pt},shorten <= -1pt] (6) -- (4);
\end{tikzpicture}
\end{document}

which now gives:

enter image description here

4

You may use the positioning library of tikz as stated in the comments of your question. I used the shorten code in drawing arrows to connect them to the circle. Because, when you shift them, a white ugly space appears between the arrow and circle.

enter image description here

%pdflatex
\documentclass[margin=0.5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}
\pgfmathsetmacro{\shift}{0.25ex}

\node [draw , circle] (1) at (-0.5,3) {1};
\node [draw , circle] (2) at (0.5,3) {2};
\node [draw , circle] (3) at (0,2) {3};
\node [draw , circle] (4) at (0,0) {$4$};
\node [draw , circle] (5) at (0.5,1) {$5$};
\node [draw , circle] (6) at (-0.5,1) {$6$};

\draw [->] (1) -- (2);
\draw [->,shorten <=-1pt, transform canvas={xshift=-\shift,yshift=-\shift}] (1) -- (3);
\draw [->,shorten <=-1pt, transform canvas={xshift=\shift,yshift=\shift}] (3) -- (1);
\draw [->] (3) -- (2);

\draw [->] (3) -- (5);

\draw [->] (5) -- (6);
\draw [->,shorten <=-1pt, transform canvas={xshift=-\shift,yshift=\shift}] (4) -- (5);
\draw [->,shorten <=-1pt, transform canvas={xshift=\shift,yshift=-\shift}] (5) -- (4);
\draw [->,shorten <=-1pt, transform canvas={xshift=-\shift,yshift=-\shift}] (6) -- (4);
\draw [->,shorten <=-1pt, transform canvas={xshift=\shift,yshift=\shift}] (4) -- (6);

\end{tikzpicture}
\end{document}
2

With the help of the first comment, I made what I wanted (Ι made sth similar to the original drawing)! Here's the code.

        \documentclass{article}


\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes.misc,patterns,shapes.symbols,decorations.pathreplacing,decorations}

\begin{document}

%===Credits to JLDiaz for the following part=========

    \pgfdeclaredecoration{sl}{initial}{
        \state{initial}[width=\pgfdecoratedpathlength-1sp]{
            \pgfmoveto{\pgfpointorigin}
        }
        \state{final}{
            \pgflineto{\pgfpointorigin}
        }
    }

    \tikzset{parallel arrow/.style={->, 
            shorten >=2mm, shorten <=2mm, 
            decoration={sl,raise=1mm},decorate}}
%===================================================================

    \tikzset{shorten arrow/.style = {->, shorten >=2 mm, shorten <=2mm}}



    \begin{tikzpicture}
    \draw (0,3) circle (8pt)node[](1){1} ;

    \draw (3,6) circle (8pt)node[](4){4} ;
    \draw (6,3) circle (8pt)node[](3){3} ;
    \draw (0,0) circle (8pt)node[](2){2} ;
    \draw (3,3) circle (8pt)node[](5){5} ;
    \draw (3,0) circle (8pt)node[](6){6} ;

    \foreach \x in {1,3,5}
    \path (4) edge[shorten arrow] (\x);

    \foreach \x/\y in {1/2,2/1,2/6,6/2,5/6,6/5}
    \path (\x) edge [parallel arrow] (\y); 

\path (2)edge[shorten arrow] (5); 

\path (5)edge[shorten arrow] (3); 

    \end{tikzpicture}

\end{document}

enter image description here

1

A solution with :

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\[\begin{tikzcd}[%
row sep = 20mm, column sep = 20mm, % both optional, adapt as you please
cells={nodes={circle, draw}}, 
every arrow/.append style={shorten <= 1mm, shorten >= 1mm}] % both optional. Default connects the arrow directly to the circles
& 4 \arrow{dl} \arrow{d} \arrow{dr} & \\
1 \arrow[shift left]{d} & 5 \arrow[shift left]{d} \arrow{r} & 3 \\
2 \arrow[shift left]{u} \arrow{ur} \arrow[shift left]{r} & 6 \arrow[shift left]{l} \arrow[shift left]{u} & 
\end{tikzcd}\]
\end{document}

enter image description here

If the default distance for shift left is not good for you, you can just add =any_measure to it. In this case, I would define a style shifted in order to change the value in just one place.

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.