[Tex/LaTex] TikZ: position text along path

pathspositioningrotatingtext-decorationstikz-pgf

I'm trying to position a piece of text at a certain position along a multi-part path. Here's what I have been trying so far.

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
  \path[fill=red,even odd rule, postaction={decorate},decoration={markings,mark=at position .2 with {\node (0,20) {my text};}}] (0,0) -- (5,5) -- (5,0);
\end{tikzpicture}
\end{document}

I would like the node to be rotated so that the text is aligned with the path at the position of the node. I can of course manually rotate the node, but I would like this to happen automatically.

Please Note: I know about decorations.text, which could achieve what I'm trying to do. The problem here is that I would need to specify exactly at which relative position the text should appear (for example at 20% of the path length). If you know a way how to achieve this using decorations.text – please go ahead and compile an answer. Otherwise, I'll stick with this node marking hack.

Best Answer

For the extra bit;

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.text}

\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
\draw (-2,-2) rectangle (6,6);
\path[draw=red,
      postaction={decorate},
      decoration={text along path,
                  text=my text,
                  text align={left indent={0.2\dimexpr\pgfdecoratedpathlength\relax}}
                  }
                  ] 
(0,0) -- (5,5) -- (5,0);
\end{tikzpicture}
\end{document}

Notice that with text marking decorations, the position of the text is where the first letter is but not the center of the text. I've added a quick tick decoration to demonstrate every 0.2-long segment but it is not in the code above. Also possible to center by negative phantom spaces etc. but I guess a small tweak won't hurt much if a centering is needed.

enter image description here