0

Consider the following LaTeX manuscript featuring a simple TikZ graph (the graph's code is essentially copied from p. 260 of the TikZ & PGF manual for version 3.0.1a).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{quotes}
\begin{document}
    \begin{tikzpicture}
        \graph{a ->[red, "foo"] b --[thick, "bar"] {c, d};};
    \end{tikzpicture}
\end{document}

The resulting rendered picture is (not to scale)

                                        A TikZ graph

Referring to this example, the manual points out that the label "bar" is applied to both edges leaving node b. If we wish to specify different labels for these two edges, we should precede the respective node option list with a greater-than sign, as follows (again, essentially copied from p. 260):

\documentclass[convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{quotes}
\begin{document}
    \begin{tikzpicture}
        \graph{a -> b -- {c[> "foo"], d[> "bar"']};};
    \end{tikzpicture}
\end{document}

The resulting rendered picture is (not to scale)

                                        A TikZ graph with different labels on different incoming edges.

The manual goes on to say (p. 260):

Symmetrically, preceding the options by < causes the options and labels to apply to the “outgoing” edges of the node

To illustrate this, the following code is given (on p. 260), to which I have added what's necessary to make it a complete and compilable LaTeX program.

\documentclass[convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{quotes}
\begin{document}
    \begin{tikzpicture}
        \graph{a[< red] -> b -- {c[> blue], d[> "bar"']};};
    \end{tikzpicture}
\end{document}

The resulting rendered picture is (not to scale)

                                        A TikZ graph with a label on an outgoing edge.

Now here's what gets me. In the previous example, where different labels were attached to different incoming edges, the > notation had to be used. In contrast, in the last example the same effect can be achieved without the < notation, by placing the red label on the edge:

\graph{a ->[red] b -- {c[> blue], d[> "bar"']};};

In fact, I cannot think of any circumstance where this would not be the case, i.e. I cannot think of a case that the < notation is necessary and cannot be rewritten by placing the options directly on the edge.

Could anyone please give me an example where the use of the < notation is necessary, or at least advantageous over placing the options directly on the edge?

1
  • I skimmed this earlier while I was meant to be doing something else. (Well, that's almost always true, but more so.) Now I've read it more carefully: why do you think there's any asymmetry here? Neither > nor < is strictly necessary, but the lack of each would create exactly similar problems (modulo the axis of symmetry, of course).
    – cfr
    Aug 1, 2017 at 1:24

1 Answer 1

1

There is no asymmetry; the cases are exactly symmetrical. So I'm not sure what the puzzle is here. Or, rather, I'm not sure why one case should be puzzling, but the other not. Either both are well-motivated or neither is.

Compare the problem revealed by your example,

\begin{tikzpicture}
  \graph {a ->[red, "foo"] b --[thick, "bar"] {c, d};};
\end{tikzpicture}

with that revealed by the corresponding case,

\begin{tikzpicture}
  \graph { { {a, b } -- [thick, "bar"] c} -> [red, "foo"] d};
\end{tikzpicture}

symmetrical problems

This can be solved, as you say, in the first case, with

\begin{tikzpicture}
  \graph {a ->[red, "foo"] b -- {c[> "foo"], d[> "bar"']};};
\end{tikzpicture}

and, in an exactly symmetrical way, in the second case, with

\begin{tikzpicture}
  \graph { { {a[< "foo"], b[< "bar"'] } -- c} -> [red, "foo"] d};
\end{tikzpicture}

symmetrical solutions

This syntax is not necessary in either case. But neither are all kinds of conveniences, such as styles and the rectangle operation when constructing paths.

Such short cuts make it much easier to write consistent, flexible code, just as semantic mark-up does generally. For example,

\begin{tikzpicture}
  \graph { g -- a[< red, > {densely dashed, bend left}] -> {b, c, d} ; f -- a -- h -- a};
\end{tikzpicture}

could be written without the < and >, but it would be a lot messier, a lot easier to end up with an inconsistent result and a lot harder to maintain, read and adapt.

marked up code output

But there is absolutely no asymmetry here, in either problem or solution.

Complete code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,quotes}
\begin{document}
\begin{tikzpicture}
  \graph {a ->[red, "foo"] b --[thick, "bar"] {c, d};};
\end{tikzpicture}
\begin{tikzpicture}
  \graph { { {a, b } -- [thick, "bar"] c} -> [red, "foo"] d};
\end{tikzpicture}
\begin{tikzpicture}
  \graph {a ->[red, "foo"] b -- {c[> "foo"], d[> "bar"']};};
\end{tikzpicture}
\begin{tikzpicture}
  \graph { { {a[< "foo"], b[< "bar"'] } -- c} -> [red, "foo"] d};
\end{tikzpicture}
\begin{tikzpicture}
  \graph { g -- a[< red, > {densely dashed, bend left}] -> {b, c, d} ; f -- a -- h -- a};
\end{tikzpicture}
\end{document}
9
  • When I mentioned an example where the > notation had to be used, I wasn't talking about the example you used in the answer, but about \graph{a -> b -- {c[> "foo"], d[> "bar"']};};, but in hind sight it can be rewritten as \graph{a -> b --["foo"] c, b --["bar"] d};};
    – Evan Aad
    Aug 1, 2017 at 1:32
  • @EvanAad That is in my answer except that the first edge is red and labelled, also. But the use of > is the same. I copied your examples from the question. You don't have to use the > there. You could manage without it.
    – cfr
    Aug 1, 2017 at 1:35
  • @EvanAad I only made the first edge red because otherwise, it looked as if the solution required losing the red, which is obviously not the case.
    – cfr
    Aug 1, 2017 at 1:37
  • Actually, I'm getting an error with \graph{a -> b --["foo"] c, b --["bar"] d}; that TikZ does not know the key '/tikz/"{foo}"'. Do you know why?
    – Evan Aad
    Aug 1, 2017 at 1:44
  • @EvanAad that's not in my answer.
    – cfr
    Aug 1, 2017 at 1:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .