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;
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.