3

How can I move a "text along path" vertically? Currently, I'm using a path with modified endpoints to place the text, and then draw the actual line.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations,decorations.text}
\begin{document}
\begin{tikzpicture}
  \node (p1) at (0,0) {1};
  \node (p2) at (5,0) {2};

  \path[
    postaction={
      decorate,
      decoration={
        text along path,
        text align=center,
        text={|\small\color{blue}|My curved text}
      }
    }
  ]
  (p1.25) to [bend left=15] (p2.155);

  \draw (p1) edge[<->,bend left=15] (p2);
\end{tikzpicture}
\end{document}

Bonus points if the solution works regardless of the path orientation (moving the letters along the path's normal, i.e. a line perpendicular to the path).

4

The PGF documentation pgfmanual.pdf.gz, in the Text Decorations section, says:

Each character is positioned using the center of its baseline. To move the text vertically (relative to the path), the additional transform key should be used.

transform should actually be a hyperlink to de documentation for /pgf/decoration/transform=<transformations>, which is in the Positioning Decorations Relative to the To-Be-Decorate Path section.

So if you want to just move the text vertically, use transform={yshift=1cm}:

\draw[
  <->,
  postaction={
    decorate,
    decoration={
      text along path,
      text align=center,
      transform={yshift=1cm},
      text={|\small\color{blue}|My curved text}
    }
  }
]
(p1) to [bend left=15] (p2);

If you want to move the text along a line perpendicular to the path, then use the /pgf/decoration/raise key, like so:

% I Increased bending and set text align=left so we can se the effect better.
\draw[
  <->,
  postaction={
    decorate,
    decoration={
      text along path,
      text align=left,
      raise=1cm,
      text={|\small\color{blue}|My rounded text}
    }
  }
]
(p1) to [bend left=100] (p2);

Note also the /pgf/decoration/mirror=<boolean> key, also described in the Positioning Decorations Relative to the To-Be-Decorate Path section, which puts the decoration on the other side of the path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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