2

How would I create something like this in TikZ, such that I could reuse the template to create other diagrams like this one?

enter image description here

Update: Using the code from Gonzalo Medina, I get the following error:

! Package pgfkeys Error: I do not know the key '/tikz/myline/.pic' and I am going to ignore it. Perhaps you misspelled it.
See the pgfkeys package documentation for explanation.

The actual code is:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand\Intent[1]{%
  \textbf{Intent:}~#1%
}
\newcommand\Trigger[1]{%
  \textbf{Trigger:}~#1%
}

\begin{document}

\begin{tikzpicture}[
myline/.pic={
  \draw[ultra thick] 
    ++(2.5pt,5pt) -- 
    ++(-5pt,-5pt) --
    ++(5pt,0pt) --
    ++(-5pt,-5pt)
    ;
    \node[anchor=west,font=\itshape,text width=3cm,align=left,xshift=10pt] {#1};
  },
mynode/.style={
  text width=4cm,
  align=left,
  anchor=west
  },
arr/.style={
  ->,
  >=latex
  }
]
\node[mynode] (l1) {\Intent{lorem ipsum}};
\node[mynode,right=of l1] (r1) {\Trigger{lorem ipsum}};
\node[mynode,below=of r1] (r2) {Some other text};
\node[mynode,below=of r2] (r3) {Some other text};
\node[mynode,left=of r3] (l2) {\Intent{lorem ipsum}};
\node[below=of r3] (r4) {Done};

\draw[arr] (r1) -- (r2);
\draw[arr] (r2) -- coordinate (aux) (r3);
\draw[arr] (r3) -- (r4);

\pic at (aux) {myline={some text goes here}};
\end{tikzpicture}

\end{document}

Not sure if it matters, but my latex version is:

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (MiKTeX 2.9)

1 Answer 1

5

There's a number of possibilities to do this. Below I show a simple approach using \nodes and the positioning library; the "bend" sign was done using a pic path; defining styles you can easily set the aspect for the various elements of the drawing:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand\Intent[1]{%
  \textbf{Intent:}~#1%
}
\newcommand\Trigger[1]{%
  \textbf{Trigger:}~#1%
}

\begin{document}

\begin{tikzpicture}[
myline/.pic={
  \draw[ultra thick] 
    ++(2.5pt,5pt) -- 
    ++(-5pt,-5pt) --
    ++(5pt,0pt) --
    ++(-5pt,-5pt)
    ;
    \node[anchor=west,font=\itshape,text width=3cm,align=left,xshift=10pt] {#1};
  },
mynode/.style={
  text width=4cm,
  align=left,
  anchor=west
  },
arr/.style={
  ->,
  >=latex
  }
]
\node[mynode] (l1) {\Intent{lorem ipsum}};
\node[mynode,right=of l1] (r1) {\Trigger{lorem ipsum}};
\node[mynode,below=of r1] (r2) {Some other text};
\node[mynode,below=of r2] (r3) {Some other text};
\node[mynode,left=of r3] (l2) {\Intent{lorem ipsum}};
\node[below=of r3] (r4) {Done};

\draw[arr] (r1) -- (r2);
\draw[arr] (r2) -- coordinate (aux) (r3);
\draw[arr] (r3) -- (r4);

\pic at (aux) {myline={some text goes here}};
\end{tikzpicture}

\end{document}

enter image description here

A version without the pic path (for older PGF/TikZ versions):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand\Intent[1]{%
  \textbf{Intent:}~#1%
}
\newcommand\Trigger[1]{%
  \textbf{Trigger:}~#1%
}
\newsavebox\myline
\savebox\myline{
\tikz\draw[ultra thick] 
    ++(2.5pt,5pt) -- 
    ++(-5pt,-5pt) --
    ++(5pt,0pt) --
    ++(-5pt,-5pt)
    ;
}

\begin{document}

\begin{tikzpicture}[
mynode/.style={
  text width=4cm,
  align=left,
  anchor=west
  },
arr/.style={
  ->,
  >=latex
  }
]
\node[mynode] (l1) {\Intent{lorem ipsum}};
\node[mynode,right=of l1] (r1) {\Trigger{lorem ipsum}};
\node[mynode,below=of r1] (r2) {Some other text};
\node[mynode,below=of r2] (r3) {Some other text};
\node[mynode,left=of r3] (l2) {\Intent{lorem ipsum}};
\node[below=of r3] (r4) {Done};

\draw[arr] (r1) -- (r2);
\draw[arr] (r2) -- coordinate (aux) (r3);
\draw[arr] (r3) -- (r4);

\node at (aux) (bend) {\usebox\myline};
\node[anchor=west,right=0pt of bend,font=\itshape] {some text goes here};
\end{tikzpicture}

\end{document}
4
  • Looks awesome! However, I am unable to compile the .pic part, I've updated my question. Commented May 19, 2014 at 13:52
  • @MathiasVorreiterPedersen Please update your PGF/TikZ package. Commented May 19, 2014 at 13:55
  • @MathiasVorreiterPedersen You need TikZ 3.0. Looks like you have not updated miktex for some months.
    – Ignasi
    Commented May 19, 2014 at 13:55
  • @MathiasVorreiterPedersen I updated my answer providing a version without the pic path; this will work with your version of PGF/TikZ, although you should consider updating it as soon as possible. Commented May 19, 2014 at 14:01

You must log in to answer this question.

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