17

I have a curved arrow and want to put text inside of it (having the same curve as the arrow, of course). If the text is longer than the arrow, the text should be put on multiple lines (optimally with the arrow automatically getting thicker appropriately). See figure below.

(How) can I do this?

enter image description here


Update:

I now use

  \coordinate (specRoot) at (-10,0);
  \coordinate (testTreeRoot) at (0,0);
  \draw[->, >=latex, blue!20!white, line width=15pt, bend left]
  (specRoot) to (testTreeRoot);
  \path [decorate,decoration={text along path, text={traverse part of
      the STS and heuristically choose the best test tree}}]
     [out=30] (specRoot) to [in=130] (testTreeRoot);

But how can I combine the decorated text along the path and the actual arrow?

How can I do a carriage return, i.e. decorate two lines of text along a single path?


Update:

And now I use the following, in the file lazyOTFoverviewSmall.tex:

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.2cm, semithick, mypostaction/.style 2 args={ 
        decoration={
            text align={
                left indent=#1},
                text along path,
                text={#2}
             },
         decorate
         }
  ]

  \begin{scope}[shift={(-10cm,0cm)}]
      \node[state] (specq0) {$q_0$};
  \end{scope}
  \begin{scope}
      \node[state] (q0) {$q_0$};
  \end{scope}

  \coordinate (specRoot) at (-10,0);
  \coordinate (testTreeRoot) at (0,0);

  \draw[-latex, blue!20!white, line width=5ex, bend left]
  (specRoot) ++(1cm,1cm)
  to (testTreeRoot) ++(-1cm,1cm);
  \path [postaction={mypostaction={1cm}{traverse part of the STS}},
postaction={mypostaction={1cm}{and heuristically choose the best test
    tree}, /pgf/decoration/raise=-3mm}]
     [out=30] (specRoot) ++(1cm,1cm) to [in=130] (testTreeRoot) ++(-1cm,1cm);
\end{tikzpicture}

and in master.tex I have:

\usepackage{tikz}
\usetikzlibrary{decorations.text}
\usetikzlibrary{backgrounds,shapes} %pictures
\usetikzlibrary{arrows,automata}

....

\begin{document}

...

\begin{figure}[hbt]
  \centering
  \scalebox{.7}{\input{gfx/MBT/lazyOTFoverviewSmall.tex}}
  \caption{Overview of Lazy On-the-fly MBT}\label{fig:lazyOTFoverview}
\end{figure}

....
3
  • I have tried tex.stackexchange.com/questions/58510/…, but the text will not be curved in those cases :( Commented Oct 5, 2012 at 14:34
  • 1
    You can use Torbjørn's answer with a text decoration instead of a node.
    – percusse
    Commented Oct 5, 2012 at 14:37
  • There's some offset parameter for the text along path decoration. You could probably shift the first half of the text up, and the second half down via a postaction Commented Oct 6, 2012 at 21:55

2 Answers 2

13

TikZ is trying hard but text decorations are not really perfect as the text is decomposed into individual letters and spaces then boxed and rotated. So in general it needs further tweaks to make it look good. The main obstacle is the large arrowhead that changes the bending of the path to fit the arrowhead so the path needs to be adjusted manually. Here is a quick demo but I would recommend different paths for each line to be placed.

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}[mypostaction/.style 2 args={
                         decoration={
                              text align={
                                    left indent=#1},
                                    text along path, 
                                    text={#2}
                                    },
                           decorate
                        }
                    ]
  \coordinate (specRoot) at (-10,0);
  \coordinate (testTreeRoot) at (0,0);
  \draw[-latex, blue!20!white, line width=5ex]  (specRoot) to[in=135,out=45] (testTreeRoot);

  \path [postaction={mypostaction={1cm}{traverse part of the STS}},
         postaction={mypostaction={1cm}{and heuristically choose the best test tree},
         /pgf/decoration/raise=-3mm}]
    (specRoot) to [in=120,out=45] (testTreeRoot);
\end{tikzpicture}
\end{document}

enter image description here

9
  • Looks great. Unfortunately, I get the pdflatex error ERROR: Package pgfkeys Error: I do not know the key '/pgf/decoration/text align' and I am going to ignore it. Perhaps you misspelled it. I did use \usetikzlibrary{decorations.text} and he seems to find that library, since that line doesn't give errors. Commented Nov 20, 2012 at 16:50
  • @DaveBallakauser750378 Can you include your own MWE by editing your question? This is working without any problems on my computer. I'm using TikZ version 2.10.
    – percusse
    Commented Nov 20, 2012 at 17:13
  • MWE = Minimal Working Environment? I have included an SFE (small failing environment), hope my bug jumps right into your eye ;) Commented Nov 20, 2012 at 17:27
  • @DaveBallakauser750378 Your code also works (though the result is a little skewed). You can put \listfiles command somewhere in your preamble and check the log file for the TikZ.
    – percusse
    Commented Nov 20, 2012 at 17:34
  • 2
    @DaveBallakauser750378 Your TikZ is outdated. You need to upgrade to v2.10.
    – percusse
    Commented Nov 20, 2012 at 18:47
4

The answer below uses the wheelchart package, which I wrote.

The text in the arrow is given by the third variable. This text is denoted by \WCvarC and used in the key arc data. Here, \\ can be used to split the text over multiple lines.

This text is centered in the arc with the key arc data pos=0.5.

The arrow is obtained with the key slices end arrow={1}{-1}.

text in arc data with arrow

\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\wheelchart[
  arc data=\WCvarC,
  arc data angle shift=2,
  arc data expand=f,
  arc data pos=0.5,
  data=,
  radius={4}{5},
  slices end arrow={1}{-1},
  slices style={\WCvarB,draw=black,very thick},
  start half,
  total angle=60
]{1/blue!20/text that is curved and\\can be on multiple lines}
\end{tikzpicture}
\end{document}

Edit: Text from an external file can be placed in the arc data by first saving this text in a macro using for example the catchfile package (see Read a file and store its contents in a variable).

\begin{filecontents}{testfile.tex}
text from an\\external file
\end{filecontents}
\documentclass[border=6pt]{standalone}
\usepackage{catchfile}
\usepackage{wheelchart}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\CatchFileDef{\mytext}{testfile}{\endlinechar=-1 }
\wheelchart[
  arc data=\mytext,
  arc data angle shift=2,
  arc data expand=f,
  arc data pos=0.5,
  data=,
  radius={3}{4},
  slices end arrow={1}{-1},
  slices style={\WCvarB,draw=black,very thick},
  start half,
  total angle=60
]{1/red!20}
\end{tikzpicture}
\end{document}

arc data with text from an external file

The text from the command \lipsum[1] can not be placed directly in the arc data because it is unexpandable. This can be solved by using the macros \lipsum_get_paragraph:n and \lipsum_get_sentences:nnV from the lipsum package.

\documentclass[border=6pt]{standalone}
\usepackage{lipsum}
\usepackage{wheelchart}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\ExplSyntaxOn
\edef \testa { \lipsum_get_paragraph:n { 1 } }
\edef \testb
  {
    \lipsum_get_sentences:nnV { 1 } { 1 } \testa \\
    \lipsum_get_sentences:nnV { 2 } { 2 } \testa
  }
\ExplSyntaxOff
\wheelchart[
  arc data=\testb,
  arc data angle shift=2,
  arc data expand=f,
  arc data pos=0.5,
  data=,
  radius={7}{8},
  slices end arrow={1}{-1},
  slices style={\WCvarB,draw=black,very thick},
  start half,
  total angle=90
]{1/green!20}
\end{tikzpicture}
\end{document}

arc data with lipsum

3
  • 1
    May I ask if it is possible to add a text via \input command? I also tried to add the very well known \lipsum[1] instead of your demo text but without success. Thanks!
    – mario1000
    Commented Aug 9 at 18:39
  • 1
    @mario1000 See the updated answer. Commented Aug 10 at 16:54
  • 1
    If one ask a magician the magician makes it happen. Thanks a lot for you help!!!!
    – mario1000
    Commented Aug 10 at 17:32

You must log in to answer this question.

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