2

I can put labels onto normal edges fine, but when the edge has a style applied to it, the label is no longer applied.

Any idea what is going on/how to fix this?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,quotes}
\begin{document}
\tikz[hv path/.style = {to path={-| (\tikztotarget)}}]
\graph[grow down sep, branch right = 4em] {
A ->["this prints"] B ->{C,D};
A ->[hv path,"this doesn't"] D;
}; 
\end{document}
Stephen
  • 23

1 Answers1

1

The nodes are actually applied, however they do not show up as the to path declaration in hv path misses the \tikztonodes macro which will then expand to the nodes that has been collected at some point by the quotes library.

The full and correct definition of hv path is

hv path/.style = {to path={-| (\tikztotarget) \tikztonodes}

The nodes are by default placed at pos = .5 (= midway) along the path. At normal line-tos this is at the actual middle of the line. With the orthogonal paths -| and |- this is at the corner. The position pos = .75 (= near end) is at the midway point of the second part. (See also Node on a jointed TikZ path.)

The key swap (or its short-cut ') can be used to place a node along a path at the other side. (The graph uses internally the auto option that defaults to auto=left. The swap key swaps this to auto=right and vice versa.)

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs,quotes}
\begin{document}
\tikz[hv path/.style = {to path={-| (\tikztotarget) \tikztonodes}}]
  \graph[grow down sep, branch right = 4em] {
    A ->["this prints", '] B ->{C,D};
    A ->[hv path,"this doesn't" near end] D;
  }; 
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821