3

I am trying to get into TikZ and pgf to create figures and graphs. In the package there is the \graph command, which provides a simple yet power full interface to draw graphs and trees. However I can't seem to get the math mode working with it.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,graphs,graphdrawing}
\usegdlibrary{layered}
\begin{document}
    \tikz\graph[layered layout]{a -- b};
\end{document}

works just as intended, producing

compiled output of above code However I want to have it display formulas and Greek letters as labels of nodes or edges, such as \delta or x\cdot (1-x). Changing above to

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,graphs,graphdrawing}
\usegdlibrary{layered}
\begin{document}
    \tikz\graph[layered layout]{$a$ -- b};
\end{document}

or using $\delta$ or similar will crash on compilation. In particular above code would crash with

File ended while scanning use of \tikz@cc@parse@factor.

I toyed around with it and tried to make it work, but I can't seem to find the solution. How can I have formulas and Greek letters as names of nodes in my graph?

4

The node text with math can be given with quotes:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,graphs,graphdrawing}
\usegdlibrary{layered}
\begin{document}
    \tikz\graph[layered layout]{"$\delta a$" -- "$x\cdot(1-x)$"};
\end{document}

Result

  • wow, that was a lot simpler then I expected – FirefoxMetzger Sep 24 '15 at 17:57

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.