# How to draw rectangle edge label in tikz?

I want to draw something like this. How to get that rectangle edge label?

This is the MWE.

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=15mm]{geometry}
\usepackage{calc}
\usetikzlibrary{matrix,arrows}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}

\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm,thick]

\node[initial,state]        (A) []                          {};
\node[state]         (B) [right of=A]                       {};

\path[->] (A)  edge []    node []         {} (B);

\end{tikzpicture}

\end{document}


How to get the Label?

-
I think you can do \node[draw, shape = rectangle] –  dustin Jun 30 '13 at 17:32
Just use \node [draw=black, text width=3.0cm] {Label}; The text width is only if you want a larger box than the text as you have show. If this is being placed along an edge use midway, above option to place the node midway and above the line. –  Peter Grill Jun 30 '13 at 17:32
@dustin : Where should add that code? –  tikzlearner Jun 30 '13 at 17:45
@PeterGrill: Where should put that code? –  tikzlearner Jun 30 '13 at 17:45

On way would be to just add it to the \path:

\path[->] (A) edge [] node [draw=black, text width=3.0cm, midway, yshift=2ex]  {Label} (B);


## Code:

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=15mm]{geometry}
\usepackage{calc}
\usetikzlibrary{matrix,arrows}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}

\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm,thick]

\node[initial,state]        (A) []                          {};
\node[state]         (B) [right of=A]                       {};

\path[->] (A)  edge []    node [draw=black, text width=3.0cm, midway, yshift=2ex]         {Label} (B);

\end{tikzpicture}

\end{document}

-