6

I'm basically asking this question, because the answer there is not working for the case with -- lines.

Say you have a line like so:

\draw (0,0) -- (3,3) node[sloped, midway,above]{Hey!};

Then is it possible to make a style such that the code below produces the same result as above?

\draw[heyEnd](0,0) -- (3,3);

I suspect that it should be very possible, because arrow tips makes this effect.

Full example:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \tikzset{
      heyEnd/.style={
          every edge/.style={
              edge node={node[sloped, midway,above]{Hey!}},
              draw
            }
        }
    }

    %% Intended result:
    % \draw (0,0) -- (3,3) node[sloped, midway,above]{Hey!};

    %% This works:
    % \draw[heyEnd](0,0) edge (3,3);

    % This does not, but I want it to
    \draw[heyEnd](0,0) -- (3,3);
  \end{tikzpicture}
\end{document}

(Possibly) related:

1 Answers1

8

I don't now if that's the answer you are looking for but you can of course achieve the same for -- lines with decorations.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
  \begin{tikzpicture}
    \tikzset{
      heyEnd/.style={
          every edge/.style={
              edge node={node[sloped, midway,above]{Hey!}},
              draw
            }
        },
     heyMark/.style={postaction={decorate,decoration={markings,
     mark=at position 0.5 with {\node[midway,above,sloped]{Hey!}; }}}}  
    }

    %% Intended result:
    % \draw (0,0) -- (3,3) node[sloped, midway,above]{Hey!};

    %% This works:
    \draw[heyEnd](0,0) edge (3,3);

    % This works now
    \draw[heyMark](4,0) -- (7,3);
  \end{tikzpicture}
\end{document}

enter image description here