3

I have the following problem: With the code

\documentclass[border=10pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\everymath{\displaystyle}

\begin{document}
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
  text centered, rounded corners, minimum height=4em]

\tikzstyle{line} = [-stealth, thick, draw]

\begin{tikzpicture}[node distance=5cm, text width=8em, auto]
  \node [block] (A) {Block 1};
  \node [block, right of=A] (B) {Block 2};
  \path [line] (A) edge node [midway] {Text} (B);
\end{tikzpicture}

\end{document}

I get the following image

enter image description here

The text description is not shown at the center of the arrow. It seems that the start point of the error is wrong. What do I need to do to have the arrow description at the right position (middle of arrow)?

My attempts: I can change midway to at end but this does not seem to be the right solution...

1 Answers1

2

The problem with text width=8em which takes too much space. The solution is to remove it. Therefore, the result should be

enter image description here

and the code is

\documentclass[border=10pt]{standalone}

\usepackage{tikz} \usetikzlibrary{shapes,arrows}

\everymath{\displaystyle}

\begin{document} \tikzstyle{block} = [rectangle, draw, fill=blue!20, text centered, rounded corners, minimum height=3em, minimum width=5em]

\tikzstyle{line} = [-stealth, thick, draw]

\begin{tikzpicture}[node distance=3.5cm, auto] \node [block] (A) {Block 1}; \node [block, right of=A] (B) {Block 2}; \path [line] (A) edge node [midway] {Text} (B); \end{tikzpicture}

\end{document}

I've changed minimum height=3em and node distance=3.5cm. Also, I've added minimum width=5em as the OP requested in the comment.


Update: as @Zarko mentioned in below comments, the node is already placed in the midway, therefore, there is no need to explicitly add it to the node.

CroCo
  • 5,902
  • @Cr0Co, nodes on edges are always on the middle of them, so the option [midway] of their node is surplus. – Zarko Nov 15 '15 at 14:45
  • @Zarko, I've addressed only the problem. And you're right. I will update it now. – CroCo Nov 15 '15 at 14:48