15

I want to draw an arrow between two nodes (a) and (b), and write text inside the arrow. How can I modify this command to control the size of the arrow head and insert the text?

\draw[->, >=latex, blue!20!white, line width=15pt]   (a) to (b) ; 

2 Answers 2

18

You can perfectly use the shapes library for this. Use \usetikzlibrary{shapes.arrows}. Based on an example from the TikZ manual, page 441:

\documentclass{article}

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

\begin{document}
    \begin{tikzpicture}[every node/.style={single arrow, draw=none, rotate=60}]
        \node [fill=red!50] {arrow 1};
        \node [fill=blue!50, single arrow head indent=1ex] at (1.5,0) {arrow 2};
    \end{tikzpicture}
\end{document}

This gives:

enter image description here

4
  • 2
    It is best to post a fully compilable example with a \documentclass (can use article, unless a reason to use something else), and include all the packages so that others can just cut and paste. Commented Jun 4, 2012 at 17:39
  • Thanks, but you should not use the minimal class. See Why not use the minimal class, that was why I had suggested using the article class. Commented Jun 5, 2012 at 15:28
  • It still gave the identical output, but I fixed it anyway. Thanks.
    – Ingo
    Commented Jun 5, 2012 at 16:29
  • 1
    Yeah in this case it does not matter, but better not to use minimal in general. Commented Jun 5, 2012 at 16:37
12

Those are two quite different questions, answering the one in the title:

If you simply add a node along the line, it will be printed on top of the line (unless otherwise specified). You have to change the color though, as the color specification of the \draw command also applies to the node.

For non-horizontal arrows add sloped to the node options.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (6,0);
\coordinate (c) at (45:6);

\draw[->, >=latex, blue!20!white, line width=15pt] (a) to node[black]{text} (b);
\draw[->, >=latex, blue!20!white, line width=15pt] (a) to node[black,sloped]{text} (c);
\end{tikzpicture}
\end{document}
3
  • Great, thanks! I had to specify anchor=center for this to work
    – Neil G
    Commented Oct 1, 2012 at 0:21
  • Does this also work for arrows that are not horizontal? Commented Apr 24, 2020 at 13:42
  • @fuenfundachtzig Yes, the node placement along the path doesn't depend on the direction of the line. But to get the correction rotation you need to add the sloped option to the node. (i.e. node[black,sloped]{text}). Commented Apr 24, 2020 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .