How to draw a directed graph to show the relations among some notions?
something like this?
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, matrix, positioning}
\begin{document}
\begin{tikzpicture}[>={Triangle[]}]
\matrix[matrix of nodes,
column sep={60pt},
row sep={60pt},
nodes={rectangle, anchor=center}] (s)
{
|(NM1)| NM-CPA & |(NM2)| NM-CCA1 &|(NM3)| NM-CCA1 \\
|(IND1)| IND-CPA &|(IND2)| IND-CCA1 &|(IND3)| IND-CCA2 \\
};
\draw[->] (NM2) edge (NM1)
(IND3) edge (IND2)
(IND2) edge (IND1);
\draw[->] ([xshift=-3mm]NM1.south) -- node[midway, left] {3.1}([xshift=-3mm]IND1.north);
\draw[->] ([xshift=3mm]NM2.south) -- node[midway, left] {3.1}([xshift=3mm]IND2.north);
\draw[->] ([xshift=-3mm]NM3.south) -- node[midway, left] {3.1}([xshift=-3mm]IND3.north);
\draw[<-] ([xshift=3mm]NM3.south) -- node[midway, right] {3.3}([xshift=3mm]IND3.north);
\draw[->] (NM2.north east)--node[midway,above left]{3.7} coordinate (aux) (NM3.north west);
\draw ([shift={(-1mm,-2mm)}]aux)--([shift={(1mm,2mm)}]aux);
\draw[<-] (NM2.south east)--(NM3.south west);
\draw[<-] (NM1.south east)-- node[pos=.6, above right] {3.5}coordinate (aux) (IND2.north);
\draw ([shift={(-1mm,-2mm)}]aux)--([shift={(1mm,2mm)}]aux);
\draw[->] (NM1.south)-- node[pos=.4, below left] {3.6}coordinate (aux) (IND2.north west);
\draw ([shift={(-1mm,-2mm)}]aux)--([shift={(1mm,2mm)}]aux);
\draw ([shift={(-1mm,-2mm)}]aux)--([shift={(1mm,2mm)}]aux);
\end{tikzpicture}
\end{document}
Here are two more solutions:
– one with pstricks
;
– another with tikz-cd.
\documentclass{article}
\usepackage{pst-node}
\usepackage{tikz-cd}
\usetikzlibrary{decorations.markings}
\tikzset{degil/.style={
decoration={markings,
mark= at position 0.5 with {
\node[transform shape] (tempnode) {/};}},
postaction={decorate}}}
\begin{document}
%
\[ \texttt{pstricks: }\qquad\psset{arrows=->, arrowinset=0.25, linewidth=0.6pt, nodesep=5pt, labelsep=2pt, shortput =tablr}
\everypsbox{\scriptstyle}
\begin{psmatrix}[colsep = 2cm, rowsep = 1.5cm]
\textrm{NM-CPA} & \textrm{NM-CCA1} & \textrm{NM-CCA1} \\
\textrm{IND-CPA} & \textrm{IND-CCA1} & \textrm{IND-CCA1}
%% horizontal rules
\ncline{1,2}{1,1}
\ncline[offset = 1ex]{1,2}{1,3}\ncput{/}\naput[npos = 0.35]{3.7}
\ncline[offset = 1ex]{1,3} {1,2}
\ncline{2,2}{2,1}\ncline{2,3}{2,2}
%% vertical rules
\ncline{1,1}{2,1}\nbput{3.1} \ncline{1,2}{2,2}\naput{3.1}
\psset{labelsep = 2.5ex}
\ncline[offset = 1ex]{1,3}{2,3}\nbput{3.1}
\ncline[offset = 1ex]{2,3}{1,3}\nbput{3.1}
%% oblique rules
\psset{nodesepA = 8.5pt, nodesepB = 8pt, offset = -1.4ex, nrot =: 0, labelsep = 0.5ex}%
\ncline{1,1}{2,2}\nbput[npos = 0.3]{3.6}\ncput[nrot =: 22]{/}
\ncline{2,2}{1,1}\nbput[npos = 0.3]{\rotatedown{3.5}}\ncput[nrot =: 22]{/}
\end{psmatrix}
\]
\bigskip
\[ \texttt{tikz-cd: }\qquad\begin{tikzcd}[arrows =-stealth, column sep = 1.5cm, row sep = 1.2cm, sep = huge, cells = {inner ysep = 2ex}]
\textrm{NM-CPA} \dar["3.1",swap]\drar[shift left = -1.4ex, "3.6", near start, swap, degil] & \textrm{NM-CCA1}\lar \rar[shift left = 1ex, "3.7", near start,degil] \dar["3.1"]
& \textrm{NM-CCA1}\lar[shift left = 1ex]\dar[shift left = 1ex, "3.1"]\\%
\textrm{IND-CPA} & \textrm{IND-CCA1}\lar\ular[shift left = -1.4ex, " 3.5", near start, swap, degil] & \textrm{IND-CCA1} \lar \uar[shift left = 1ex, "3.1"]
\end{tikzcd}
\]
\end{document}
Another solution with tikz-cd
.
To refine the position of the sloped arrows I've used start anchor=..., end anchor=...
, whereas "/"{anchor=center,sloped}
is taken from this answer.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{positioning, arrows.meta}
\tikzcdset{arrow style=tikz, diagrams={>=Stealth}}
\begin{document}
\[
\begin{tikzcd}[row sep=10ex,column sep=4em]
\textrm{NM-CPA}
\ar[d,"3.1"{left=2pt}]
\ar[rd,"/"{anchor=center,sloped}, swap, "3.6"{below left=0pt and 6pt}, start anchor=-40, end anchor=160]
&
\textrm{NM-CCA1}
\ar[l]
\ar[d,"3.1"{right=2pt}]
\ar[r,"/"{anchor=center,sloped},"3.7"{above=4pt}, shift left]
&
\textrm{NM-CCA1}
\ar[l,shift left]
\ar[d,"3.1"{left=2pt}, shift right]
\\
\textrm{IND-CPA}
&
\textrm{IND-CCA1}
\ar[l]
\ar[lu,"/"{anchor=center,sloped}, start anchor=140, end anchor=-17, swap,"3.5"{above right=0pt and 6pt}]
&
\textrm{IND-CCA2}
\ar[l]
\ar[u,"3.3"{right=2pt}, shift right]
\\
\end{tikzcd}
\]
\end{document}