51

I'm using the decorations library to put bended text along a path. That works fine. However, I'd like to have the bended text as a node, so that I can later use it as a reference (for instance to draw a line to it). Is that possible? How do I define the nodes's name?

Here you have a MWE:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}

\node at (0,0) (nodeA) {A};
\node at (2,2) (nodeB) {B};

\draw (nodeA) -- (nodeB);

\draw [decoration={text along path,
    text={path text},text align={center}},decorate]  (nodeA) -- (nodeB);

    \node at (0,2) (nodeC) {C};
    \draw [->] (nodeC) -- (.8,1.2);

\end{tikzpicture}

\end{document}

In the last bit, where a line is drawn from (nodeC) to the "path text", I had to use a coordinate, but I'd like to be able to use the a node reference.

The picture looks like this:

MWE result

7
  • 4
    Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you.
    – Mensch
    Commented Oct 10, 2012 at 14:48
  • Unfortunately, text decorations seperate the text into individual letters and put them into distinct boxes. So if you can provide an MWE then we can try to see if we can squeeze in a coordinate or a node.
    – percusse
    Commented Oct 10, 2012 at 16:22
  • @percusse: I've edited my question adding a MWE. I didn't manage to put the code in a comment (I'm new in this forum). Commented Oct 11, 2012 at 9:13
  • 3
    Editing the question is always better than putting the code in a comment - you did the right thing. Commented Oct 11, 2012 at 9:14
  • What shape would you like the node to be? Making it follow the shape of the text would be quite hard to do. Putting coordinates at each letter would be possible, followed by fitting a rectangular node to the whole lot. An alternative would be to use the path as a reference. Commented Oct 11, 2012 at 9:17

1 Answer 1

76

If you just want the text rotated and sloped along the path, you can use the sloped option to the node, and don't need to use a decoration.

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

    \node at (0,0) (nodeA) {A};
    \node at (2,2) (nodeB) {B};
    
    \draw (nodeA) -- (nodeB);

    \draw (nodeA) -- (nodeB) node [midway, above, sloped] (TextNode) {path text};
    \node at (0,2) (nodeC) {C};
    \draw [->] (nodeC) -- (TextNode);

\end{tikzpicture}
\end{document}
2
  • That's exactly what I needed... and much easier the using decorations. Commented Oct 11, 2012 at 10:52
  • 14
    @PeterGrill I am just going to add that I use pos=.5 instead of midway for more precise alignment by percentage, because I often refer to this page and forget how to do that. Commented Apr 20, 2016 at 13:26

You must log in to answer this question.

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