2

I want to use a conditional in graph with Tikz (awesome package by the way). My solution is to repeat the node with 2 different labels :

"Urgent ?" -> ["yes"] "do something";
"Urgent ?" ->["no"] "sleep";

Is there a syntax with subgraphs to have a shorter version ? Something like :

"Urgent" {
  -> ["yes"] "do something";
  ->["no"] "sleep";
}

Thanks !

Minimal working example :

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{graphdrawing}
\usegdlibrary{layered}
\usetikzlibrary{quotes}

\begin{document}
\tikz \graph [layered layout]
{
  "Urgent ?"
  -> ["yes"] "do something";
  "Urgent ?"
  ->["no"] "sleep";
};
\end{document}
  • 2
    Maybe "Urgent ?" -> { "do something" [>"yes"], "sleep" [>"no"] }; – Mark Wibrow Aug 16 '18 at 10:31
  • Perfect ! If you can post it as an answer, I'll mark it as accepted. – alex_reader Aug 16 '18 at 12:22
4

This is covered in section 19.6.5 'Placing Node Texts on Incoming Edges' ('TikZ & PGF Manual for Version 3.0.1a' p280), using the > shorthand:

\RequirePackage{luatex85}
\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{graphs}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{quotes}
\usegdlibrary{layered}

\begin{document}
\tikz \graph [layered layout]
{
  "Urgent ?" -> { "do something" [>"yes"], "sleep" [>"no"] };
};
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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