Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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

1 Answer 1

up vote 10 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.