6

This question already has an answer here:

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

enter image description here

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?

marked as duplicate by Dr. Manuel Kuehner, Mensch, Troy, Bobyandbob, Schweinebacke Nov 5 '17 at 15:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3
\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)

enter image description here

  • I think one cannot forget pos, anchor and below. – Viesturs Nov 5 '17 at 13:53
  • Could you add these details to your answer? – Viesturs Nov 5 '17 at 13:58
  • @Viesturs, see edited answer. – Zarko Nov 5 '17 at 15:08

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