# How to draw a request response message in tikz?

I am pretty new to tikz. I need a request response message in tikz. I have attached the image. I need the image should be generated as shown in the attached figure. I have tried a lot, but struck in between. Here is the source.

 \documentclass[12pt,a4paper,twoside]{report}
\usetikzlibrary{shapes, arrows, positioning}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[shape=rectangle, text width=2cm, minimum height=3cm, minimum width=2cm, node distance=5cm, align=center, ultra thick, color=black]
\node [draw](sp) {Service Provider};
\node [draw,right=of sp] (sc) {Service Consumer};
\draw [->] (sp) -- node [right] {request service} (sc) ;
\draw [->] (sc.west) +(0,-1em) coordinate (b1) -- (sp.east |- b1);
\end{tikzpicture}
\end{figure}
\end{document}

• You need \usepackage{tikz} before \usetikzlibrary. – Torbjørn T. Aug 12 '17 at 14:23
• Okay. Thanks for the correction. Will do that. – Mishra S Aug 12 '17 at 14:24
• It can very well be done with basic latex… – Bernard Aug 12 '17 at 14:25
• @Bernard I don't have any idea regarding latex. I am more interested to draw this using tikz. – Mishra S Aug 12 '17 at 14:26
• As you please, but it's using a sledge hammer to crack a nut. – Bernard Aug 12 '17 at 14:38

You're fairly close actually. First, you do of course need to have \usepackage{tikz} before \usetikzlibrary{..}.

As for the diagram, instead of having all those settings directly in the tikzpicture options, make a new style with stylename/.style={<list of settings>}, and apply that style to your two nodes. Because you had them like that, it seems they applied to the node with request service as well, which is why that node had a linebreak in it. Finally, place the request/response for nodes above the path, instead of right. I also shifted the first line up, in the same way you shifted the second one down.

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
mybox/.style={
text width=2cm,
minimum height=3cm,
minimum width=2cm,
node distance=5cm,
align=center,
ultra thick,
draw},
myarrow/.style={
->,
>=stealth,
thick
}
]
\node [mybox](sp) {Service Provider};
\node [mybox,right=of sp] (sc) {Service Consumer};
\draw [myarrow] (sp.east) +(0,-1em) coordinate (b1) -- node [above] {response for service} (sc.west |- b1) ;
\draw [myarrow] (sc.west) +(0,1em) coordinate (b1) --node[above] {request for a service} (sp.east |- b1);
\end{tikzpicture}
\end{figure}
\end{document}

• I removed the packages and libraries that were unnecessary. – Torbjørn T. Aug 12 '17 at 14:34

Just to show how easy to do it with basic LaTeX:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{old-arrows}
\usepackage[svgnames]{xcolor}

\begin{document}
$\setlength{\fboxsep}{0pt} \setlength{\fboxrule}{0.8pt}\fcolorbox{DarkSeaGreen}{white}{\begin{tabular}{c} \\ Service\\ provided \\[3ex] \end{tabular}} \begin{matrix} \xrightarrow[]{\makebox[4cm]{\normalsize request for service}}\\[-1ex] \xleftarrow[{\makebox[4cm]{\normalsize response for service }}]{} \end{matrix} \fcolorbox{DarkSeaGreen}{white}{\begin{tabular}{c} \\ Service\\ assumed \\[3ex] \end{tabular}}$%
\end{document}


• I would suggest an \fbox instead of \hlines and vertical rules (look at the corners). – Torbjørn T. Aug 12 '17 at 17:42
• You're right. I forgot to check this point. I've changed my code accordingly. Thanks for the suggestion! – Bernard Aug 12 '17 at 18:26
• Thanks for editing, @Zarko. I definitely should check before posting! – Bernard Aug 12 '17 at 19:15

so similar to Torbjørn T. answer that I was doubt to publish because I was to late for 3 min:

 \documentclass[12pt,a4paper,twoside]{report}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
node distance = 2mm and 55mm,
> = Stealth,
box/.style = {rectangle, draw, thick, fill=white,
text width=2cm, minimum height=3cm,