2

I need to decorate a path with some text that includes math symbols. I followed this example, which works fine as long as I only include text. Here is the MWE (minor changes compared to example to replace \def\myshift by raise=):

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.text}

\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=circle,draw] {$One$}; 
\node (Two) at (3,0) [shape=circle,draw] {$Two$};
\draw [->,thick,postaction={decorate,decoration={text along path,text align=center,raise=2pt,text={$b$}}}] (One) to [bend right=45]  (Two);
\draw [->,thick,postaction={decorate,decoration={text along path,text align=center,raise=-7pt,text={$a$}}}] (One) to [bend left=45] (Two);
\end{tikzpicture}

\end{document}

However, as soon as I replace a by \alpha (as an example), the MWE does not compile anymore. It seems to hang and when I interrupt it with ctrl-C, I get:

! Interruption.
<to be read again> 
                   \let 
l.12 ...\alpha$}}}] (One) to [bend left=45] (Two);

(I'm running pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019).)

  • @Schrödinger's cat: I updated my MacTeX distribution before posting, so I'm also using the latest available version (log file shows Package: pgf 2019/12/21 v3.1.5a (3.1.5a)). Maybe my post is confusing - since the MWE I posted is the code that works, but it breaks if I change a to \alpha? – user1362373 Dec 31 '19 at 17:13
  • My bad. I didn't read the question carefully. – user194703 Dec 31 '19 at 17:16
2

Put braces around the macros. Why? Because in the manual v3.1.5 on p. 659 it says

enter image description here

Once I add braces, there is no problem.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.text}

\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=circle,draw] {$One$}; 
\node (Two) at (3,0) [shape=circle,draw] {$Two$};
\draw [->,thick,postaction={decorate,decoration={text along path,text
align=center,raise=2pt,text={${\beta}$}}}] (One) to [bend right=45]  (Two);
\draw [->,thick,postaction={decorate,decoration={text along path,text
align=center,raise=-7pt,text={${\alpha}$}}}] (One) to [bend left=45] (Two);
\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |
0

Not exactly an answer ... Always in my list of packages for the math teacher, this one is called tkz-graph. You need to know some options from TikZ.

\documentclass[border=.25cm]{standalone}
\usepackage{tkz-graph}

\begin{document}
 \begin{tikzpicture}
   \SetGraphUnit{4}
   \Vertex{One}
   \EA(One){Two}
   \Edge[style={<-,bend left},labelstyle={above},label=$\beta$](Two)(One) 
   \Edge[style={<-,bend right},labelstyle={below},label=$\alpha$](Two)(One)
\end{tikzpicture}
\end{document}

enter image description here

With one line of code you get the graph below (if you need probability graph or example of graph theory)

\documentclass[border=.25cm]{standalone}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
  \grProb{A}{B}{NO}{SO}{WE}{EA}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

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.