0

Here I have drawed a DAG(s). If possible I want to cut it with a curved lined.

My code:

\documentclass[journal,onecolumn]{IEEEtran}
\usepackage{hyperref}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,positioning, arrows.meta}
\usetikzlibrary{shapes.geometric, arrows, shadows, decorations.text}

\begin{document} \begin{figure}[!htp] \centering \begin{tikzpicture} [vertex/.style={circle,draw=black,fill=white}, node distance=2cm, on grid, >=latex ] % \draw[gray!50] (-1,-2) grid (5,2); \node[vertex] (A) {$J5$}; \node[vertex,above left=1cm and 1cm of A] (B) {$J4$}; \node[vertex,below=of B] (C) {$J3$}; \node[vertex,left=of A] (D) {$J2$}; \node[vertex,left=of D] (F) {$J1$}; \draw[->] (C) edge (A) (B) edge (A) (D) edge (C) (D) edge (B) (F) edge (D); \end{tikzpicture} \end{figure} \end{document}

Output:

enter image description here

Wanted output:

Example-1 Example-2
enter image description here enter image description here

Related: how to draw a cut through a graph in latex

alper
  • 1,389

1 Answers1

2

Well, you need to find the start and end points of your cuts somehow. Here I'm just using the intersections of perpendicular lines through your nodes.

One cut is just a straight line, the other one is a curve around J2 which is done via bend left and a min distance.

I'll provide two cut line styles: one uses the random steps decoration, the one is just a dashed line.

Code

\documentclass[tikz]{standalone}
%\documentclass[journal,onecolumn]{IEEEtran}
%\usepackage{hyperref}
%\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, positioning, arrows.meta, angles}
\tikzset{
  cut line/.style={
    rounded corners=\pgfdecorationsegmentamplitude,
    decoration={name=random steps}, decorate},
%  cut line/.style=dashed,
}
\pgfmathsetseed{693069} % reproducable output
\begin{document}
%\begin{figure}[!htp]
%    \centering
\begin{tikzpicture}[
  vertex/.style={circle, draw=black}, node distance=2cm, on grid, >=Latex]
\node[vertex]                               (J5) {$J5$};
\node[vertex, above left=1cm and 1cm of J5] (J4) {$J4$};
\node[vertex, below=of J4]                  (J3) {$J3$};
\node[vertex, left=of J5]                   (J2) {$J2$};
\node[vertex, left=of J2]                   (J1) {$J1$};
\path[->] (J1) edge (J2) (J2) edge (J4) edge (J3) (J4) edge (J5) (J3) edge (J5);
\draw[red, cut line] (J2|-J4) -- (J5|-J3);
\end{tikzpicture}
\begin{tikzpicture}[
  vertex/.style={circle, draw=black}, node distance=2cm, on grid, >=Latex]
\node[vertex]                               (J5) {$J5$};
\node[vertex, above left=1cm and 1cm of J5] (J4) {$J4$};
\node[vertex, below=of J4]                  (J3) {$J3$};
\node[vertex, left=of J5]                   (J2) {$J2$};
\node[vertex, left=of J2]                   (J1) {$J1$};
\path[->] (J1) edge (J2) (J2) edge (J4) edge (J3) (J4) edge (J5) (J3) edge (J5);
\draw[red, cut line] (J2|-J4) to[bend left=45, min distance=1.2cm] (J2|-J3);
\end{tikzpicture}
%\end{figure}
\end{document}

Output

random steps

enter image description here enter image description here

dashed

enter image description here enter image description here

Qrrbrbirlbel
  • 119,821
  • Is it also possible to sligthly shift the drawn line in y-axis? In the cases of if I have a label in the center, the line overwrites it – alper Aug 09 '23 at 14:34
  • 1
    @alper You can always adjst the position with a transformation, say \draw[red, cut line] ([xshift=4mm]J2|-J4) -- ([yshift=4mm]J5|-J3); – Qrrbrbirlbel Aug 09 '23 at 19:35