1

Description

I want to connect two nodes with a directed edge (or path). The edge shall 1) bend AND have 2) a decoration - but only in the middle of the edge. A draft looks like this:

intended results

Attempt 1

I achieved 1) and 2) separately. But I don't achieve 1) + 2) combined or with poor results.

As far as I understand the path decoration is a global property and therefore applies to the complete path. As is written here tikz manual, chapter 11.2.3 and in several posts.

Attempt 2

I tried to make use of two dummy notes A and B and create a path between them with a zigzag line
\documentclass[margin=10pt]{standalone}
\usepackage{tikz} %drawings
\usetikzlibrary{arrows,positioning, decorations.pathmorphing}  %drawings positioning
\usepackage[siunitx]{circuitikz}

\begin{document}    
    \begin{tikzpicture}
        \draw [help lines] (0,0) grid (15,10);  
        
        % CONTENT NODES
        \node[align=center] (agent) at (2,5){Agent :: Mental Models};   
        \node[align=center] (action) at (7, 5){Actions/\\ Communications};
        
        % DUMMY NODES
        \node(A) at (4.5, 3){};
        \node(B) at (5.5, 3){};
        
        % ZIGZAG LINE BETWEEN DUMMY NODES
        \path [decoration={zigzag, post length=0.1cm, pre length=0.1cm, amplitude=5}] 
                (A) edge[decorate] node[below] {takes} (B);
        
        % CONNECT DUMMY NODES TO CONTENT NODES WITH ADJUSTED MARGIN
        \path[shorten >=-.3cm]
            (action) edge[bend left] (B);
        
        \path[shorten <=-0.3cm]
            (A) edge[->, bend left] (agent);
        
    \end{tikzpicture}
\end{document}  

But the problem is that there is no closed path. The result is ugly. Refer to the disconnection of the zigzag segment

Failed solution to connect zigzag segement

Attempt 3

I tried to make use of the package

\usepackage[siunitx]{circuitikz}

to draw a complete path. This works perfectly for straight paths. But I couldn't use it for a bend path

Attempt 4

I tested to draw the same as SVG in inkscape and import it in the document. This has at least two shortcomings: There is a lot of text in the SVG and correct alignment of text boxes with text is painful. Also, in terms of maintenance, etc., I prefer "clean code" over workaround.

1 Answer 1

2

You can use some pre length and post length, as you already do, but in conjunction with pre=curveto and post=curveto, which will curve the segments that are straight in your example.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz} %drawings
\usetikzlibrary{arrows.meta,bending,positioning, decorations.pathmorphing}  %drawings positioning

\begin{document}    
    \begin{tikzpicture}
        \draw [help lines] (0,0) grid (15,10);  
        
        % CONTENT NODES
        \node[align=center] (agent) at (2,5){Agent :: Mental Models};   
        \node[align=center] (action) at (7, 5){Actions/\\ Communications};
        
        % DUMMY NODES
        \node(A) at (4.5, 3){};
        \node(B) at (5.5, 3){};
        
        % ZIGZAG LINE BETWEEN DUMMY NODES
        \draw [decoration={zigzag,pre=curveto,post=curveto, 
            post length=1cm, pre length=1cm, amplitude=5},decorate,-{Latex[bend]}] 
                (action) to[bend left=60] node[below=0.5ex] {takes} (agent);
        
        
    \end{tikzpicture}
\end{document}  

enter image description here

You can make it a fraction of the path length.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz} %drawings
\usetikzlibrary{arrows.meta,bending,positioning,decorations.markings, decorations.pathmorphing}  %drawings positioning

\begin{document}    
    \begin{tikzpicture}
        \draw [help lines] (0,0) grid (15,10);  
        
        % CONTENT NODES
        \node[align=center] (agent) at (2,5){Agent :: Mental Models};   
        \node[align=center] (action) at (7, 5){Actions/\\ Communications};
        
        % DUMMY NODES
        \node(A) at (4.5, 3){};
        \node(B) at (5.5, 3){};
        
        % ZIGZAG LINE BETWEEN DUMMY NODES
        \path [preaction={decorate,decoration={markings,
            mark=at position 0 with {\xdef\mypgfdecoratedpathlength{\pgfdecoratedpathlength}}}},
            postaction={decorate,draw,
            decoration={zigzag,pre=curveto,post=curveto, 
            post length=0.4*\mypgfdecoratedpathlength, 
            pre length=0.4*\mypgfdecoratedpathlength, 
            amplitude=5},decorate,-{Latex[bend]}
            }] 
                (action) to[bend left=60] node[below=0.5ex] {takes} (agent);
        
    \end{tikzpicture}
\end{document}  
1
  • Thank you! This solution works perfectly. Commented Mar 17, 2021 at 7:14

You must log in to answer this question.

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