Friday, February 10, 2012

Using tikz-uml to create uml diagrams in latex

At Uni we are learning UML for documenting our products. Therefore we need at tool to create these. I had a hard time finding a good, free, gui tool, so I settled for a LaTeX/TikZ solutions, since we use LaTeX for reports anyway. I will here briefly describe how to get started using tikz-uml, as the package is called.

First step is to go and download tikz-uml here.

Assuming you are on linux, unzip the tikz-uml.sty file in a folder: ~/texmf/tex/latex/tikz-uml/. Windows people should be able to find a similar folder in their C:\Program Files\Miktex folder somewhere, as far as I recall.

Now run the command:

texhash ~/texmf
to make Latex aware of the newly installed package. (I do not know how to do this in Windows. Possibly through the Miktex package manager?)

Now you are ready to get stated using tikz-uml. Usage examples are found here. A simple template to get started could be:

\documentclass[12pt,article]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\linespread{1.05}
\usepackage{tikz}
\usepackage{tikz-uml} 
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
\begin{umlsystem}[x=0, y=0]{Name of system} 
% Code from official documentation goes here...
\end{umlsystem}
% And here
\end{tikzpicture}

\end{document}

Example of Use Case model

Here is the code for a use case diagram using tikz-uml:

\documentclass[12pt,article]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\linespread{1.05}
\usepackage{tikz}
\usepackage{tikz-uml} 
\usepackage{amsmath}
\usepackage{savetrees}
\begin{document}

\begin{figure}[h!]
\begin{tikzpicture}
\begin{umlsystem}{Schedule}
\umlusecase[x=-3]{Check Request}
\umlusecase[x=3]{Ask Constraints}
\umlusecase[x=-2,y=-2]{Deny Request}
\umlusecase[x=3, y=-2]{Collect Constraints}
\umlusecase[x=-3,y=-4]{Determine Schedule}
\umlusecase[x=3,y=-4]{Merge Constraints} 
\umlusecase[y=-6]{Resolve Conflicts}
\end{umlsystem}

\umlactor[x=-8]{Initiator}
\umlactor[x=-8,y=-6]{Participant A}
\umlactor[x=8]{Participant B}
\umlactor[x=8,y=-6]{Conflict Resolver} 

\umlassoc{Initiator}{usecase-1}
\umlassoc{Initiator}{usecase-3}
\umlassoc{Participant A}{usecase-5}
\umlassoc{Participant B}{usecase-2}
\umlassoc{Participant B}{usecase-4}
\umlassoc{Conflict Resolver}{usecase-7}

\umlextend{usecase-2}{usecase-3}
\umlinclude{usecase-5}{usecase-7}
\end{tikzpicture}
\caption{Example of Use case diagram using tikz-uml. Examlpe from the book Requirements Engineering by Axel van Lamsweerde.}
\end{figure}

\end{document}
and the result:

More examples may come as we learn more about it.

6 comments:

  1. Thank you! A good explanation how to install the package under windows is given in http://tex.stackexchange.com/a/2066

    ReplyDelete
  2. Found a UML software version that is usable in Linux, Ubuntu called creately that can easily draw UML diagrams. This is method is good but normal user is bit reluctant to try this method.

    ReplyDelete
    Replies
    1. The problem with Creately is that it is a closed platform, with tikz-uml you have full control. If you know Latex then you have a great deal of power to do adjust things, whereas in Creately you limited by its methodology. Creately does export to SVG, but then you still have a lot of work to do in editing a graphic file. Why go through all this work, when with tikz-uml you can edit the file using latex commands, and then the UML diagram can incorporate directly into you latex document!
      Furthermore, Creately is not free and it isn't worth the money...its diagrams are not very professional, they are kindergartenish!

      Delete
  3. What a coincidence, I also have the same interests as those listed at the beginning of the blog post and I have enjoyed reading the article and I am looking forward to reading more programming articles from this site. I will, therefore, bookmark this site so that I can visit it occasionally to read both new and old articles as I outsource Help with Page Setting.

    ReplyDelete
  4. Online biology essay services have come up with Biology Essay Writing Services for biology research paper writing service students in order for them to score straight A’s in their custom biology research paper services.

    ReplyDelete