0

I am trying to reproduce the following chart with Tikz:

LQN plot draft.

Here it is so far what I obtained:

LQN plot with Tikz.

with the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{chains,shapes.multipart}
\usetikzlibrary{shapes, fit}
\usetikzlibrary{automata,positioning}



\tikzset{
    activity/.style={
        draw,
        rectangle,
        minimum height = 0.8cm,
        minimum width = 1.5cm
    },
}

\begin{document}

\begin{tikzpicture}
% Outer parallelogram (TaskA)
\draw (0,0) -- (-100:6cm) --++ (0:6cm) --++ (80:6cm) -- (0,0);
\node at (5,-0.5) {TaskA};

% Inner parallelogram (EntryA)
\draw (1.5,0) --++ (-100:1cm) --++ (0:2cm) --++ (80:1cm);
\node at (2.3,-0.5) {EntryA};

% Activities 
\node[activity] (s) at (2.3,-2) {source};
\node[circle, draw] (plus) at (2.3, -3.5) {+};
\node[activity] (c1) at (1, -5) {choice1};
\node[activity] (c2) at (3.6, -5) {choice2};

\draw [->] (2.3,-1) -- (s.north);
\draw [->] (s.south) -- (plus.north);
\draw [->] (plus.south east) -- (c2.north);
\draw [->] (plus.south west) -- (c1.north);



% TaskB
\draw (0,-8) --++ (-100:2cm) --++ (0:6cm) --++ (80:2cm) -- (0,-8);
\node at (2.8,-9.5) {TaskB};

% EntryB1
\draw (0.5,-8) --++ (-100:1cm) --++ (0:2cm) --++ (80:1cm);
\node (eB1) at (1.3,-8.5) {EntryB1};

% EntryB2
\draw (3.5,-8) --++ (-100:1cm) --++ (0:2cm) --++ (80:1cm);
\node (eB2) at (4.3,-8.5) {EntryB2};

\node[circle,draw] (pA) at (8, -5) {ProcA};
\node[circle,draw] (pB) at (8, -10) {ProcB};

\draw [->] (c1.south) -- (eB1.north);
\draw [->] (c2.south) -- (eB2.north);

\end{tikzpicture}

\end{document}
  • How do I align the bottom arrows so that they point at the center of, respectively, EntryB1 and EntryB2?
  • How do I add the two arrows pointing from the outer parallelograms to the circles "ProcA" and "ProcB"?
  • How do I add the overscript "0.5" on the arrows in the center of the plot?
2
  • What do you mean by aligning the arrows? Right now they are exactly pointing to the center of EnteryB(1/2) node respectively. Do you want the arrows to be parallel?
    – antshar
    Jun 27 at 11:42
  • I want the arrows to aim to the north/center of the parallelogram around EntryB1/EntryB2 (as in the plot I drawn by hand). Thanks in any case!
    – Robb1
    Jun 27 at 14:30

1 Answer 1

1

As for arrows with a text above 0.5, it can be achieved by adding node {$0.5$} inside the path. It will look something like that

\draw [->] (plus.south east) -- node[anchor=south west]{$0.5$} (c2.north);

The other two bullet points can be solved in two ways:

  1. Without any concrete changes in your exact code, by adding local bounding box to your outer parallelograms, you can call it afterwards and treat as a node. enter image description here

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage{float}
    \usepackage{amsmath}
    \usepackage{amsthm}
    \usepackage{tikz}
    \usetikzlibrary{chains,shapes.multipart}
    \usetikzlibrary{shapes, fit}
    \usetikzlibrary{automata,positioning}
    \usetikzlibrary{intersections}
    
    
    
    \tikzset{
        activity/.style={
            draw,
            rectangle,
            minimum height = 0.8cm,
            minimum width = 1.5cm
        },
    }
    
    \begin{document}
    
    \begin{tikzpicture}
    % Outer parallelogram (TaskA)
    \draw[local bounding box=pOA] (0,0) -- (-100:6cm) --++ (0:6cm) --++ (80:6cm) -- (0,0);
    \node at (5,-0.5) {TaskA};
    
    % Inner parallelogram (EntryA)
    \draw (1.5,0) --++ (-100:1cm) --++ (0:2cm) --++ (80:1cm);
    \node at (2.3,-0.5) {EntryA};
    
    % Activities 
    \node[activity] (s) at (2.3,-2) {source};
    \node[circle, draw] (plus) at (2.3, -3.5) {+};
    \node[activity] (c1) at (1, -5) {choice1};
    \node[activity] (c2) at (3.6, -5) {choice2};
    
    \draw [->] (2.3,-1) -- (s.north);
    \draw [->] (s.south) -- (plus.north);
    \draw [->] (plus.south east) -- node[anchor=south west]{$0.5$} (c2.north);
    \draw [->] (plus.south west) -- node[anchor=south east]{$0.5$} (c1.north);
    
    
    
    % TaskB
    \draw[local bounding box=pOB] (0,-8) --++ (-100:2cm) --++ (0:6cm) --++ (80:2cm) -- (0,-8);
    \node at (2.8,-9.5) {TaskB};
    
    % EntryB1
    \draw[local bounding box=e1] (0.5,-8) --++ (-100:1cm) --++ (0:2cm) --++ (80:1cm);
    \node (eB1) at (1.3,-8.5) {EntryB1};
    
    % EntryB2
    \draw[local bounding box=e2] (3.5,-8) --++ (-100:1cm) --++ (0:2cm) --++ (80:1cm);
    \node (eB2) at (4.3,-8.5) {EntryB2};
    
    \node[circle,draw] (pA) at (8, -5) {ProcA};
    \node[circle,draw] (pB) at (8, -10) {ProcB};
    
    \draw [->] (c1.south) -- (e1.north);
    \draw [->] (c2.south) -- (e2.north);
    
    \draw [->, shorten <= -18pt] (pOA.east) -- (pA);
    \draw [->, shorten <= -5pt] (pOB.east) -- (pB);
    
    
    \end{tikzpicture}
    
    \end{document}
    

    However, local bounding box creates a rectangular box, so in order to make arrows pointing from outer parallelograms, you need use shorten <= and eyeball the length to make it look like its actually connected

  2. The second approach that I personally suggest, doesn't have the issues with eyeballing. It uses the shapes library as well as fit one. Both of them apparently are already loaded. This way, you no longer have to create parallelograms with a path, but use a node shape. This way, you can simply draw arrows as you would normally do and they will be connected just like they should. enter image description here

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage{float}
    \usepackage{amsmath}
    \usepackage{amsthm}
    \usepackage{tikz}
    \usetikzlibrary{chains,shapes.multipart}
    \usetikzlibrary{shapes, fit}
    \usetikzlibrary{automata,positioning}
    
    
    \begin{document}
    
    \begin{tikzpicture}[
    every node/.style={draw, inner sep=8pt},
    parallelogram/.style={draw, trapezium, trapezium left angle=80, trapezium right angle=-80}
    ]
    
    % Outer parallelogram (TaskA)
    \node[draw=none] (tA) at (5,-0.5) {TaskA};
    
    \node[parallelogram] (eA) at (2.3,-0.5) {EntryA};
    
    % Activities 
    \node (s) at (2.3,-2) {source};
    \node[circle] (plus) at (2.3, -3.5) {+};
    \node (c1) at (1, -5) {choice1};
    \node (c2) at (3.6, -5) {choice2};
    
    \draw [->] (eA) -- (s.north);
    \draw [->] (s.south) -- (plus.north);
    \draw [->] (plus.south east) -- node[draw=none, inner sep=1pt, anchor=south west]{$0.5$} (c2.north);
    \draw [->] (plus.south west) -- node[draw=none, inner sep=1pt, anchor=south east]{$0.5$} (c1.north);
    
    % TaskB
    \node[draw=none] (tB) at (2.8,-9.5) {TaskB};
    
    % EntryB1
    \node[parallelogram] (eB1) at (1.3,-8.5) {EntryB1};
    
    % EntryB2
    \node[parallelogram] (eB2) at (4.3,-8.5) {EntryB2};
    
    \node[circle, inner sep=2pt] (pA) at (8, -5) {ProcA};
    \node[circle, inner sep=2pt] (pB) at (8, -10) {ProcB};
    
    \draw[->] (c1.south) -- (eB1.north);
    \draw[->] (c2.south) -- (eB2.north);
    
    \node[parallelogram, xshift=10pt, fit=(eA) (c1) (c2)] (pOA) {};
    
    \node[parallelogram, fit=(eB1) (eB2) (tB)] (pOB) {};
    
    \draw[->] (pOA) -- (pA);
    \draw[->] (pOB) -- (pB);
    
    \end{tikzpicture}
    
    \end{document}
    

    Edit:

    About discussed top alignment in the comments.

    With the second approach, outer parallelograms are nodes, created with fit tikz library, that basically creates a node that fits inside all the listed content. Since it's a node, it can have padding set by inner sep option. However, there is no way to control only one side (left, right, top, bottom), so you in order to achieve that effect you can shit the node by the amount of padding and get the desired alignment.

    Since innner sep can be changed at any point you decide so, that shifting will have to be modified as well. Although there is a more versatile way of doing that, using \pgfkeysvalueof{/pgf/inner ysep} that extracts the current padding so that the shifting will be updated automatically in respect to the changes of inner sep enter image description here

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage{float}
    \usepackage{amsmath}
    \usepackage{amsthm}
    \usepackage{tikz}
    \usetikzlibrary{chains,shapes.multipart}
    \usetikzlibrary{shapes, fit}
    \usetikzlibrary{automata,positioning}
    
    
    \begin{document}
    
    \begin{tikzpicture}[
    every node/.style={draw, inner sep=8pt},
    parallelogram/.style={draw, trapezium, trapezium left angle=80, trapezium right angle=-80}
    ]
    
    % Outer parallelogram (TaskA)
    \node[draw=none] (tA) at (5,-0.5) {TaskA};
    
    \node[parallelogram] (eA) at (2.3,-0.5) {EntryA};
    
    % Activities 
    \node (s) at (2.3,-2) {source};
    \node[circle] (plus) at (2.3, -3.5) {+};
    \node (c1) at (1, -5) {choice1};
    \node (c2) at (3.6, -5) {choice2};
    
    \draw [->] (eA) -- (s.north);
    \draw [->] (s.south) -- (plus.north);
    \draw [->] (plus.south east) -- node[draw=none, inner sep=1pt, anchor=south west]{$0.5$} (c2.north);
    \draw [->] (plus.south west) -- node[draw=none, inner sep=1pt, anchor=south east]{$0.5$} (c1.north);
    
    % TaskB
    \node[draw=none] (tB) at (2.8,-9.5) {TaskB};
    
    % EntryB1
    \node[parallelogram] (eB1) at (1.3,-8.5) {EntryB1};
    
    % EntryB2
    \node[parallelogram] (eB2) at (4.3,-8.5) {EntryB2};
    
    \node[circle, inner sep=2pt] (pA) at (8, -5) {ProcA};
    \node[circle, inner sep=2pt] (pB) at (8, -10) {ProcB};
    
    \draw[->] (c1.south) -- (eB1.north);
    \draw[->] (c2.south) -- (eB2.north);
    
    \node[parallelogram, xshift=10pt, yshift=-\pgfkeysvalueof{/pgf/inner ysep}, fit=(eA) (c1) (c2)] (pOA) {};
    
    \node[parallelogram, inner ysep=3pt, xshift=-3pt, yshift=-\pgfkeysvalueof{/pgf/inner ysep}, fit=(eB1) (eB2) (tB)] (pOB) {};
    
    \draw[->] (pOA) -- (pA);
    \draw[->] (pOB) -- (pB);
    
    \end{tikzpicture}
    
    \end{document}
    
2
  • Thank you very much! Very clear and what I needed :) Just one question: is it possible to align the inner parallelograms (EntryX) to the top line of the outer ones (TaskX) with the second approach?
    – Robb1
    Jun 28 at 7:25
  • 1
    @Robb1 see the edited post.
    – antshar
    Jun 28 at 8:06

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.