1

I thought that the following two graphs are the same.

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\begin{document}
    \tikz\graph{1--{2,3}};
    \tikz\graph{1--[]{2,3}};
\end{document}

But they result

and .

It is supposed to be so? I found this because I need to insert some edge options like [red,thick]. But usually I create empty nodes like \tikz\graph{/--[foobar]{/,/}}; to make it short. Any alternatives?

Symbol 1
  • 36,855
  • Besides accepting an answer you should also up vote it: How do you accept an answer? and perhaps How does accepting an answer work? – Peter Grill Jan 06 '15 at 06:43
  • @PeterGrill Sorry I was looking for that syntax in the manual. It does solve my problem. The point is that I cannot get its logic... – Symbol 1 Jan 06 '15 at 06:47
  • If it solved your problem, then it certainly deserves an up vote. If you have trouble understanding the logic or the syntax you could either ask the one who answered it via a comment or even post a new question specifically on the syntax or logic. If you are having difficulty understanding it, chances are good that others will to, so a separate question on the syntax might be helpful to others as well. – Peter Grill Jan 06 '15 at 07:07

2 Answers2

3

The answer by Kpym is not correct. There is indeed such a syntax for styling edges as described in §19.6.1 Options For All Edges Between Two Groups (p. 276):

When you write … ->[options] … somewhere inside your graph specification, this typically cause one or more edges to be created between the nodes in the chain group before the -> and the nodes in the chain group following it. The options are applied to all of them.

The OP is simply missing a space after the ] and before the {. Here is a working example:

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs}
\begin{document}
    \tikz\graph{1--{2,3}};
    \tikz\graph{1--[] {2,3}}; % ← space added between ] and {

    % This also works:
    \tikz\graph{1--[]{2,3} }; % ← space added between } and }
\end{document}

hftf
  • 2,283
  • How come missing a space is a problem in TikZ? I mean, if it does need such a space, why does the spaceless code compile? – Symbol 1 Apr 12 '15 at 17:34
  • @Symbol1 Good question. I also don't know the answer to that. – hftf Apr 12 '15 at 17:42
  • Anyway I appreciate your confirmation. (about that --[] is the official syntax.) I shall do some research myself and we will see whether this question has received enough attention or not. – Symbol 1 Apr 12 '15 at 17:49
  • 2
    Even \tikz\graph{1--[]{2,3} }; works. Checking the code, something goes awry with \pgfutil@ifnextchar as it sees the 2 as the next character and not the { (= \bgroup). Very weird. – Qrrbrbirlbel Apr 12 '15 at 18:27
2

This is not the syntax to styling edges. Here is an example of how to do it :

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}
    \tikz\graph{1--{2,3}};
    \tikz\graph{1--{2[>green!75!black], 3[>{thick,red}]}};
\end{document}

enter image description here

Kpym
  • 23,002