5

I am using the last example of the Chapter 3 - "Use case diagrams" TikZ-UML manual (pp. 34-35).

Please consider this MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{amsmath}

\usepackage{silence}
\WarningFilter{pgf}{Your graphic driver}        % FOR DELETE WARNING OF 'Package pgf Warning: Your graphic driver...'. From https://tex.stackexchange.com/q/63522/152550

\usepackage{tikz-uml}
\tikzumlset{fill usecase=white}

\usepackage{pdflscape}

\begin{document}

\begin{landscape}
    \begin{tikzpicture}
        \begin{umlsystem}[x=6] {Name of the system}
            \umlusecase[name=a,width=2.5cm] {Use case a}
            \umlusecase[name=b,x=6,width=2.5cm] {Use case b}
            \umlusecase[name=c,x=6,y=-3,width=2.5cm] {Use case c}
            \umlusecase[name=d,y=-3,width=2.5cm] {Use case d}
        \end{umlsystem}

        \umlactor[y=-1] {Actor 1}
        \umlactor[y=-3] {Actor 2}
        \umlactor[x=18] {Actor 3}

        \umlassoc{Actor 1}{a}
        \umlassoc{Actor 2}{a}

        \umlextend{a}{b}
        \umlinclude{c}{d}
    \end{tikzpicture}
\end{landscape}

\end{document}

What I have

If possible, I want to implement three changes:

  1. Put Name of the system label outside the rectangle (above it).
  2. Put ≪extend≫ and ≪include≫ labels above its lines.
  3. Bend down (or up) the association between Actor 3 and Use case 1 (insted of \umlassoc{Actor 3}{a} because it overlaps with \umlextend{a}{b}).

I want this:

What I want

From what I have seen, the manual says nothing about it.

(@N. Kielbasiewicz please read this question!)

Thanks!!

  • 2
    You will need to use normal TikZ commands. The problem is figuring out what tikz-uml is actually doing (especially the node names). Remember that everything tikz-uml does can be done using TikZ, albeit with more work. – John Kormylo Nov 30 '18 at 14:57
  • 1
    Just to support what @JohnKormylo is saying: I had a quick look at the internals of that style file and am not surprised that you find it hard to adjust things to become as you like them to be. Among other things, it does nest tikzpictures when creating the actors. That means that when you start customizing things, there is great chance things go uncontrollable. If I was you, I'd just copy the actor code, define a pic using it, and then do an ordinary tikzpicture. – user121799 Nov 30 '18 at 17:32
  • @marmot do you confirm that it is currently impossible to make those changes only with tikz-uml loaded? I am planning to contact tikz-uml's creator. – manooooh Dec 1 '18 at 8:03
  • @marmot I found \newcommand{\umlextend}[3][] in line 2810 of the tikz-uml.sty file. I do not see how to move the extend label above of the relation (anyway you neither). – manooooh Dec 1 '18 at 8:13
  • @JohnKormylo thank you, it is very useful! Do you know how to mix tikz-uml commands with normal tikz? – manooooh Dec 1 '18 at 8:16
3

As suggested by John Kormylo, you can do this by mixing in normal TikZ drawing commands.

  1. For the name of the system, set the title of the umlsystem empty, and immediately after \end{umlsystem} add

    \node [above] at (current bounding box.north) {Name of the system};
    
  2. While one could redefine the \umlrelation macro to place the "stereo" next to the lines, it might be just as easy to just draw them manually with

    \draw [tikzuml dependency style] (a) -- node[above] {$\ll \text{extend} \gg$} (b);
    \draw [tikzuml dependency style] (d) -- node[above] {$\ll \text{include} \gg$} (c);
    

    The coordinates corresponds to the name you've given your four \umlusecases (with name=a etc.).

  3. The actors are placed in nodes with the name you give the actors, so the bent association between a and Actor 3 can be drawn with

    \draw [tikzuml association style] (a) to[bend right=10] (Actor 3);
    

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz-uml}
\tikzumlset{fill usecase=white}
\begin{document}

    \begin{tikzpicture}
        \begin{umlsystem}[x=6] {} % empty title
            \umlusecase[name=a,width=2.5cm] {Use case a}
            \umlusecase[name=b,x=6,width=2.5cm] {Use case b}
            \umlusecase[name=c,x=6,y=-3,width=2.5cm] {Use case c}
            \umlusecase[name=d,y=-3,width=2.5cm] {Use case d}
        \end{umlsystem}
        \node [above] at (current bounding box.north) {Name of the system};

        \umlactor[y=-1] {Actor 1}
        \umlactor[y=-3] {Actor 2}
        \umlactor[x=18] {Actor 3}

        \umlassoc{Actor 1}{a}
        \umlassoc{Actor 2}{a}


        % \umlextend{a}{b}
        % \umlinclude{c}{d}

        % manual versions of the above
        \draw [tikzuml dependency style] (a) -- node[above] {$\ll \text{extend} \gg$} (b);
        \draw [tikzuml dependency style] (d) -- node[above] {$\ll \text{include} \gg$} (c);

        % bent association
        \draw [tikzuml association style] (a) to[bend right=10] (Actor 3);
    \end{tikzpicture}

\end{document}
  • Excellent explanation! Just what I wanted. I only change $\ll \text{extend/include} \gg$ to $\ll \! \text{extend/include} \! \gg$ to get approximately the same space as the original. Many thanks! P.S. You could use your prev answer to get rid of every width=2.5cm ;) haha. – manooooh Dec 1 '18 at 22:22

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.