[Tex/LaTex] How to draw rectangle edge label in tikz

automataautomationlabelstikz-pgf

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

enter image description here

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?

Best Answer

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);

enter image description here

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}