# tikz: Rotating and positioning text relative to a line [duplicate]

This code

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
...
\path (0, 0) edge node [sloped, anchor=center, below] {line}(3, 3);
\end{tikzpicture}
\end{document}


gives the output

The text has the orientation and placement exactly as needed relative to the line which has been drawn by some other method:

 \pgfpathmoveto{\pgfpointxy{0}{0}};
\pgfpathlineto{\pgfpointxy{3}{3}};
\pgfusepath{stroke}


Hence, I need only the text and not the line. How can I achieve this?

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{quotes}
\begin{document}
\begin{tikzpicture}
\path[red]  (0,0) edge node[below,sloped] {line} (3, 3);
\path       (0,0) to [pos=0.4, sloped, "line" '] (3, 3);
\end{tikzpicture}

\begin{tikzpicture}[
every edge quotes/.append style = {anchor=north, sloped}
]
\path[red]  (0,0) edge node[below,sloped] {line} (3, 3);
\path       (0,0) to ["line"] (3, 3);
\end{tikzpicture}
\end{document}


(as supplement to percusse comment). positioning of edge labels is little bit tricky when it is in sloped orientation. in such cases, if you require exactly centered labels, you have three possibilities:

• play with manual tweaking of label position (showed in top image)
• redefine edge labels style (bottom image)
• use edge nodes (in image below is in red color, but with visible line for better orientation where are labels)

• I think one cannot forget pos, anchor and below. – Viesturs Nov 5 '17 at 13:53