Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wish to draw the graph like in the picture, however, there are three problems here, 1. how to add the words "OnMess" and "h" on top of the rectangles 2. how to add the word "ac" above the line as described in the picture 3. how to add slash to the line. enter image description here

Here is my code, however the three problems haven't solved, can someone help me?:

 \documentclass[tikz]{standalone}
\usetikzlibrary{
    shapes.geometric,
    positioning,
    fit,
    calc
}
\tikzset{
    cir/.style={
       shape=circle,
       minimum size=1em,
    },
    dia/.style={
        shape=diamond,
        minimum size=2em,
    },
    dia cross/.style={
        dia,
        path picture={
            \draw (path picture bounding box.west) -- (path picture bounding box.east)
                  (path picture bounding box.north) -- (path picture bounding box.south);
        }
    }
}
\begin{document}
\begin{tikzpicture}[
    every node/.append style={draw,minimum width=3em,minimum height=1.5em},
    >=latex
]

%%% Left side
%% nodes with text
\node(a) {get flight(gf)};
\node[below=.5 of a] (b) {book flight(bf)};

\node[right=of a]    (c) {gc};
\node[below=.5 of c] (d) {bc};

%% rectangles around nodes with text
\node[fit=(a)(b)] (ab) {};
\node[fit=(c)(d)] (cd) {};

%% top diamond
\node[dia] at ([yshift=.5cm]$(ab.north)!.5!(cd.north)$) (dia1) {};

%%% Right side
\node[right=2 of d] (f) {bh};
\node[label={[inner sep=0pt,minimum height=2ex]above:h}] at (f |- dia1) (e) {gh};

% fake f to get the same spacing as on the left side (text with draw=gray)
\node[fit=(f),draw=none] (f') {};

%%% Big rectangles
\node[inner sep=1em,fit=(ab)(cd)(dia1)] (left) {};
\node[inner sep=1em,fit=(f')(dia1.north -| e)] (right) {};

%%%the first top diamond
\node[dia cross] at ([yshift=4.5cm]$(left.south)!.5!(right.south)$) (dia0) {};
\node[above=.5 of dia0](top){fu};
\node[cir,above=.5 of top,fill=black](ini){};

%%% Diamond below
\node[dia cross] at ([yshift=-.5cm]$(left.south)!.5!(right.south)$) (dia2) {};
\node[dia,below=.5 of dia2](dia3){};
\node[right=of dia3](atc){atc;
\node[below=0.5 of dia3](ru){ru};
\node[cir,below=0.5 of ru,fill=black](end){};
%%% Arrows
\foreach \pp/\pf/\pt in {--/a/b,
                         --/c/d,
                         --/e/f,
                         --/ini/top,
                         --/top/dia0,
                         --/dia2/dia3,
                         --/dia3/ru,
                         --/ru/end,
                         --/dia3/atc,
                         -|/dia1/ab,
                         -|/dia1/cd,
                         -|/dia0/left,
                         -|/dia0/right,
                         |-/left/dia2,
                         |-/atc/ru,
                         |-/right/dia2}
\draw[
    shorten >=\pgflinewidth,
    ->
] (\pf) \pp (\pt);
\end{tikzpicture}
\end{document} 
share|improve this question
You should really only ask one question per post, and try to phrase it more generally, so other people can profit from the answers more easily. For example, you could write one question "How can I cross out a line?", with a minimal example (not the whole diagram), "How can I add a label to a line?", "How can I position text inside a rectangle?". In each case, you should add what you've tried (at least for the labeling question, there are some on this site already) – Jake Feb 14 at 9:13
To add a text, you just need to add a \node, without drawing its shape. E.g.: \node (label) at (posX, posY) {Texte}; – Lionel MANSUY Feb 14 at 9:14
For me this looks like an state transition diagramm in UML. If this is what you are trying to do TikZ-UML may be a good solution for you: ensta-paristech.fr/~kielbasi/tikzuml/index.php?lang=en – Dave Feb 14 at 10:01
You should put every node/.append style={draw,minimum width=3em,minimum height=1.5em}, >=latex} and everything it will affect in a scope. Then you can write something like \path (dia3) -- (atc) node [above, midway] {ac}; \node [below] at ([yshift=2pt]left.north) {OnMess}; outside the scope so that the nodes don't get framed. For the slashed line, see How can I strike-out arrows in tikz? – hpesoj626 Feb 14 at 10:15
You also missed a } in \node[right=of dia3](atc){atc; – hpesoj626 Feb 14 at 10:16
show 1 more comment

closed as too localized by Jake, T. Verron, Claudio Fiandrino, zeroth, lockstep Feb 14 at 10:05

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.