I had some old code in my conputer. It's not exactly what you want, but I think it could be an starting point.
First the final result:

I also had to draw some link control protocol examples and decided to create some commands
to draw frames (from A to B in previos figure)
\newcommand{\tramaok}[2]{%
\draw[trama,->] #2 --++(1.5,-2) node[above right,near start] {#1};
}
lost frames
\newcommand{\tramaperduda}[2]{%
\path #2 coordinate (a)--++(1.5,-2) coordinate (b) coordinate[midway] (c);
\draw[trama,-] (a) --(c) node[below] {#1};
\draw[trama,->] (c) -- ++(30:.5);
}
and acknowledgments (from bottom to top)
\newcommand{\ackok}[2]{%
\draw[ack,->] {#2}--++(1.5,2) node[below right,near start] {#1};
}
\newcommand{\ackperdut}[2]{%
\path #2 coordinate (a)--++(1.5,2) coordinate (b) coordinate[midway] (c);
\draw[ack,-] (a) --(c) node[above] {#1};
\draw[ack,->] (c) -- ++(-30:.5);
}
All these commands have two parameters, some label, if necessary, and its starting point.
Slope and distance are fixed. With these commands was easy to draw previous figure:
\tramaok{Tr0}{(0,2)}
\tramaok{Tr0}{(2.5,2)}
\tramaperduda{Tr1}{(5,2)}
\tramaok{Tr0}{(7.5,2)}
\ackok{Ack}{(1.5,0)}
\ackok{Ack}{(4,0)}
\ackok{Ack}{(9,0)}
\timeout{(0,2)}{(2.5,2)}
The complete code is:
\documentclass[tikz,border=2mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usetikzlibrary{calc,arrows,positioning}
\begin{document}
\tikzset{
host/.style={rectangle,rounded corners,
thick,draw=#1!60,fill=#1!15},
host/.default=blue,
trama/.style={thick,draw=#1!60,fill=#1!60},
trama/.default=purple,
ack/.style={trama=teal},
}
\newcommand{\tramaok}[2]{%
\draw[trama,->] #2 --++(1.5,-2) node[above right,near start] {#1};
}
\newcommand{\tramaperduda}[2]{%
\path #2 coordinate (a)--++(1.5,-2) coordinate (b) coordinate[midway] (c);
\draw[trama,-] (a) --(c) node[below] {#1};
\draw[trama,->] (c) -- ++(30:.5);
}
\newcommand{\ackok}[2]{%
\draw[ack,->] {#2}--++(1.5,2) node[below right,near start] {#1};
}
\newcommand{\ackperdut}[2]{%
\path #2 coordinate (a)--++(1.5,2) coordinate (b) coordinate[midway] (c);
\draw[ack,-] (a) --(c) node[above] {#1};
\draw[ack,->] (c) -- ++(-30:.5);
}
\newcommand{\timeout}[2]{%
\draw #1 --++(0,5mm);
\draw #2 --++(0,5mm);
\begin{scope}[yshift=2.5mm]
\draw[<->] #1 -- #2 node[above,midway]{\emph{Time-out}};
\end{scope}
}
\begin{tikzpicture}[>=stealth',
font=\small\sffamily]
% S&W amb etiquetes a trames
% Tout curt. Repetició trames.
% No detecta pèrdues de trames
\draw[help lines,->] (-0.2,0) node[host,left] {B}--(11.5,0);
\draw[help lines,->] (-0.2,2) node[host,left] {A}--(11.5,2);
\tramaok{Tr0}{(0,2)}
\tramaok{Tr0}{(2.5,2)}
\tramaperduda{Tr1}{(5,2)}
\tramaok{Tr0}{(7.5,2)}
\ackok{Ack}{(1.5,0)}
\ackok{Ack}{(4,0)}
\ackok{Ack}{(9,0)}
\timeout{(0,2)}{(2.5,2)}
\end{tikzpicture}
\end{document}
The following example defines \xtwoheadrightarrow
and \xtwoheadleftarrow
similar to the definitions of \xrightarrow
and \xleftarrow
:
\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
\makeatletter
\providecommand*{\twoheadrightarrowfill@}{%
\arrowfill@\relbar\relbar\twoheadrightarrow
}
\providecommand*{\twoheadleftarrowfill@}{%
\arrowfill@\twoheadleftarrow\relbar\relbar
}
\providecommand*{\xtwoheadrightarrow}[2][]{%
\ext@arrow 0579\twoheadrightarrowfill@{#1}{#2}%
}
\providecommand*{\xtwoheadleftarrow}[2][]{%
\ext@arrow 5097\twoheadleftarrowfill@{#1}{#2}%
}
\makeatother
\begin{document}
\[
A \xrightarrow[under]{over} B
\xtwoheadrightarrow[under]{over} C
\xtwoheadleftarrow[under]{over} D
\]
\end{document}

The case \rightrightarrows
/\leftleftarrows
is much more complicate. Before there is a symbol \relbar
that is used for the extensible part of the arrow. But there is no symbol for the double line case. Thus the vertical positions of the lines and their thickness is not known. The following example defines \relrelbar
for this purpose that is composed of \relbar
lowered and raised by the amount given in macro \relrelbarsep
. Therefore this macro needs to be redefined for a different font. The example uses the AMS fonts:
\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
\makeatletter
\newcommand*{\relrelbarsep}{.386ex}
\newcommand*{\relrelbar}{%
\mathrel{%
\mathpalette\@relrelbar\relrelbarsep
}%
}
\newcommand*{\@relrelbar}[2]{%
\raise#2\hbox to 0pt{$\m@th#1\relbar$\hss}%
\lower#2\hbox{$\m@th#1\relbar$}%
}
\providecommand*{\rightrightarrowsfill@}{%
\arrowfill@\relrelbar\relrelbar\rightrightarrows
}
\providecommand*{\leftleftarrowsfill@}{%
\arrowfill@\leftleftarrows\relrelbar\relrelbar
}
\providecommand*{\xrightrightarrows}[2][]{%
\ext@arrow 0359\rightrightarrowsfill@{#1}{#2}%
}
\providecommand*{\xleftleftarrows}[2][]{%
\ext@arrow 3095\leftleftarrowsfill@{#1}{#2}%
}
\makeatother
\begin{document}
\[
A \xrightrightarrows[under]{over} B
\xleftleftarrows[under]{over} C
\]
\end{document}

The numbers 0579
, ... are four arguments for \ext@arrow
that is defined by package amsmath
:
\def\ext@arrow#1#2#3#4#5#6#7{%
\mathrel{\mathop{%
\setbox\z@\hbox{#5\displaystyle}%
\setbox\tw@\vbox{\m@th
\hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
\hbox{$\scriptstyle\mkern#3mu{#7}\mkern#4mu$}%
\copy\z@
}%
\hbox to\wd\tw@{\unhbox\z@}}%
\limits
\@ifnotempty{#7}{^{\if0#1\else\mkern#1mu\fi
#7\if0#2\else\mkern#2mu\fi}}%
\@ifnotempty{#6}{_{\if0#1\else\mkern#1mu\fi
#6\if0#2\else\mkern#2mu\fi}}}%
}
Some remarks:
- The width of box
\tw@
contains the maximal width of
the text below. above and the symbol without text.
- The latter two numbers specify the margins for the texts in the measurement phase.
- The first two numbers specify the margins for the texts that is finally set and allows to insert some asymmetry of the horizontal placement because of the arrows.
Best Answer
You can use: