# tikz drawing label between nodes

I am drawing TCP packet diagram and I have been using coordinates to draw my packets and to place the socket end points (IP:port) on my diagram.

I now need to include the TCP packet type. I would like to centre this between the two (IP:port) SYN (IP:port) in the diagram like this. (Ignore _)

192.168.11.10:37064__________________SYN________________10.17.84.113:2222

<------------------------------------------------------------------------

Is the a way to center text between two nodes or should I change the way I draw the TCP flow?

This code snipet is how I have been drawing my packets.

\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\coordinate (p1a) at (13.5,7.0);
\coordinate (p1b) at (7.5,7.0);
\draw [->] (p1a) -- (p1b);
\node [anchor=east, label={[anchor=east, font=\tiny\sffamily]above:10.17.84.113:2222}] at (p1a.east) {};
\node [anchor=west, label={[anchor=west, font=\tiny\sffamily]above:192.168.11.10:37064}] at (p1b.west) {};
\end{tikzpicture}
\end{document}

• You mean \draw [->] (p1a) --node {foo } (p1b); ? – Philipp Imhof Oct 16 '15 at 6:00

This can be done in the following manner:

\documentclass[a4paper,11pt]{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
%% define the nodes directly
\node [  font=\tiny\sffamily] (p1a) at (13.5,7) {10.17.84.113:2222};
\node [ left = 3cm of p1a,  font=\tiny\sffamily] (p1bwest) (p1b) at (7.5,7.0) {192.168.11.10:37064};
%% now draw the lines
\draw [->] ([yshift=-5mm]p1a.south east) -- ([yshift=-5mm]p1b.south west);
\draw (p1a.south west) -- node[anchor=base,fill=white,font=\tiny\sffamily]{SYN} (p1b.south east);
\end{tikzpicture}
\end{document}


Adjust the -5mm in yshift suitably. I assumed that the SYN comes on the line. If not, remove the option anchor=base and put above instead.