6

Good afternoon,

Is there a way I can generate a system context diagram in LaTeX? - See below for example diagram:

Example

lockstep
  • 250,273
A T
  • 4,093
  • 3
    Take a look at http://tex.stackexchange.com/questions/9057/best-practice-for-control-flow-charts/9063#9063, that might help you get started. If you have more specific problems ("How do I influence the curvature of connecting lines?", "How can I get drop shadows behind nodes?"), feel free to add a new question. – Jake Oct 20 '11 at 04:22

2 Answers2

13

A simple example using TikZ could be:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{arrows, positioning, shadows}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[node distance=4cm, inner sep=3mm, minimum width=1.5cm, >=stealth']
\node [draw, rectangle, drop shadow, fill=white] (V) at (0,0) {VEHICLE};
\node [draw, circle, drop shadow, fill=white, text width=2cm, align=center] (C) [below right=of V] {Control Carpark (System)};
\node [draw, rectangle, drop shadow, fill=white] (D) [below right=of C] {DRIVER};

\node (ctrl1) [above=of D] {};
\node (ctrl2) [above right=of C] {};
\node (ctrl3) [right=of C] {};
\node (ctrl4) [above right=of D] {};

\path [draw, ->, dashed] (V) edge node [fill=white] {Arrival} (C)
                         edge [bend left] node [fill=white] {Exit} (C)
                         edge [bend right] node [fill=white] {Entry} (C);
\path [draw, ->, dashed] (D) edge node [fill=white] {Request} (C);
\path [draw, ->] (D) edge [bend right] node [fill=white] {Issued-Ticked} (C)
                 edge [bend left] node [fill=white] {Payment} (C)
             (C) .. controls (ctrl1) and (ctrl3) .. node [fill=white] {Ticket} (D);
\path [draw, <->] (D) .. controls (ctrl4) and (ctrl2) .. node [fill=white] {Paid-Ticket} (C);
\end{tikzpicture}
\end{figure}
\end{document}

The code can be tweaked to be more similar to the original figure, but I think the main ingredients are there:

  1. nodes to create both the boxes and 'waypoints' for the paths
  2. positioning library is loaded, so you can scale the figure more efficiently and do not have to specify explicit coordinates
  3. controls in a path to have a custom curve for the arrows and avoid overlapping
  4. shadows library for the drop shadows
  5. and the white fill to avoid text overlapping with arrow lines.

The result is this:

enter image description here

Count Zero
  • 17,424
9

The answer is an enthusiastic, yes! There are many options available, including

  • tikZ (very popular on this site, you'll probably see a solution soon)
  • PSTricks (example shown below)

The code below uses the pst-node package, see the documentation for details.

control vehicle drive mk1

\documentclass{article}

\usepackage{pst-node}

\begin{document}

\begin{pspicture}(0,0)(10,10)
 %\psgrid % useful during construction
 % draw the main nodes
 \cnodeput[shadow=true](5,5){control}{\begin{tabular}{c}Control\\Carpark\\(System)\end{tabular}}
  \rput(2,8){\rnode{vehicle}{\psshadowbox{Vehicle}}}
  \rput(8,2){\rnode{driver}{\psshadowbox{Driver}}}
  % connections from vehicle to control
  \nccurve[angleA=-90,angleB=180,linestyle=dashed,arrows=->]{vehicle}{control}
  \ncput*{Entry}
  \nccurve[angleA=-45,angleB=145,linestyle=dashed,arrows=->]{vehicle}{control}
  \ncput*{Arrival}
  \nccurve[angleA=0,angleB=125,linestyle=dashed,arrows=->]{vehicle}{control}
  \ncput*{Exit}
  % connections from drive to control
  \ncdiag[armA=2cm,armB=1cm,linearc=0.5,angleA=25,angleB=0,arrows=<->]{driver}{control}
  \ncput*{Paid-ticket}
  \nccurve[angleA=45,angleB=-15,arrows=<-]{driver}{control}
  \ncput*{Ticket}
  \nccurve[angleA=180,angleB=-90,arrows=->]{driver}{control}
  \ncput*{Issued-Ticket}
  \nccurve[angleA=135,angleB=-45,arrows=->,linestyle=dashed]{driver}{control}
  \ncput*{Request}
  % arrows
  \psnode(1,1){S}{}
  \psnode(1,3){N}{}
  \ncline[arrows=->,linestyle=dashed]{S}{N}
  \ncput*{Control Flow}
  \psnode(1,4){S1}{}
  \psnode(1,6){N1}{}
  \ncline[arrows=->]{S1}{N1}
  \ncput*{Data Flow}
\end{pspicture}

\end{document}

If you haven't used PSTricks before, there are a few things no note. Either compile the code with:

latex myfile.tex
dvips myfile.dvi
ps2pdf myfile.ps

or

xelatex myfile.tex

If you want to use pdflatex, then make your preamble look as follows:

\documentclass{article}

\usepackage[pdf]{pstricks}
\usepackage{pst-node}

\begin{document}
....

and you can then run

pdflatex -shell-escape myfile.tex

EDIT

Here's another version that is slightly more pleasing than my original (imho); it uses \ncarc rather than \nccurve

control vehicle drive mk2

\documentclass{article}

\usepackage{pst-node}

\begin{document}

\begin{pspicture}(0,0)(10,10)
 %\psgrid % useful during construction
 % draw the main nodes
 \cnodeput[shadow=true](5,5){control}{\begin{tabular}{c}Control\\Carpark\\(System)\end{tabular}}
  \rput(2,8){\rnode{vehicle}{\psshadowbox{Vehicle}}}
  \rput(8,2){\rnode{driver}{\psshadowbox{Driver}}}
  % connections from vehicle to control
  \ncarc[arcangle=-45,linestyle=dashed,arrows=->]{vehicle}{control}
  \ncput*{Entry}
  \ncarc[linestyle=dashed,arrows=->]{vehicle}{control}
  \ncput*{Arrival}
  \ncarc[arcangle=45,linestyle=dashed,arrows=->]{vehicle}{control}
  \ncput*{Exit}
  % connections from drive to control
  \ncarc[ncurv=1,arcangle=-90,arrows=<->]{driver}{control}
  \ncput*{Paid-ticket}
  \ncarc[arcangle=-25,arrows=<->]{driver}{control}
  \ncput*{Payment}
  \ncarc[ncurv=0.75,arcangle=-60,arrows=<-]{driver}{control}
  \ncput*{Ticket}
  \ncarc[arcangle=45,arrows=->]{driver}{control}
  \ncput*{Issued-Ticket}
  \ncarc[arrows=->,linestyle=dashed]{driver}{control}
  \ncput*{Request}
  % arrows
  \psnode(1,1){S}{}
  \psnode(1,3){N}{}
  \ncline[arrows=->,linestyle=dashed]{S}{N}
  \ncput*{Control Flow}
  \psnode(1,4){S1}{}
  \psnode(1,6){N1}{}
  \ncline[arrows=->]{S1}{N1}
  \ncput*{Data Flow}
\end{pspicture}

\end{document}
cmhughes
  • 100,947