# Use math font for TikZ arrow labels

I am trying to make arrow labels look like they are written in math mode. This is what I have:

This is what I want ,

I tried to use different fonts but without success. This is my code:

    \begin{tikzpicture}[node distance=2cm,inner sep=2pt,minimum size=0.5mm, bend angle=45]
\tikzstyle{place} = [ circle,draw=black,fill=black,thick ]
\tikzstyle{surd} = [circle]
\tikzstyle{pre} = [ <-,shorten <=2pt,shorten >=2pt, >=stealth', semithick]
\tikzstyle{every node} = [font=\normalsize\itshape]

\node[place] (first) {};
\node[place] (second) [right=of first] {}
edge [pre,bend right]  node [above] {$a$} (first)
edge [pre,bend left]  node [below] {$b$} (first);
\node[place] (third) [right=of second] {}
edge [pre]  node [above] {$c$} (second);
\node[surd] (surd)  [right=of third] {\Large$\surd$}
edge [pre] node [above] {$d$} (third);
\end{tikzpicture}

-
Which class are you using? Beamer perhaps? – Claudio Fiandrino Sep 6 '13 at 6:31
BTW: do not use tikzstyle, see Should \tikzset or \tikzstyle be used to define TikZ styles? – Claudio Fiandrino Sep 6 '13 at 6:37
@ClaudioFiandrino yes beamer class – tdi Sep 6 '13 at 6:39

\usefonttheme[onlymath]{serif}

to render in serif font only the math. If one does not want to type every time the $ to enter in math mode, it is possible to create a style for that: \tikzset{math mode/.style={% execute at begin node=$,%
execute at end node=$,% } }  Then, by grouping all nodes in a scope: \begin{scope}[every node/.style={math mode}] ... \end{scope}  the style will be applied "locally". An example with the math mode style active: \documentclass{beamer} \usepackage{lmodern} \usepackage{tikz} \usetikzlibrary{arrows,positioning} \usefonttheme[onlymath]{serif} \begin{document} \begin{frame}{title} Some text in sans serif font. Math, like: $$x+y=100$$ is rendered in serif font. \begin{center} \begin{tikzpicture}[node distance=2cm,inner sep=2pt,minimum size=0.5mm, bend angle=45] \tikzset{place/.style={circle,draw=black,fill=black,thick}} \tikzset{surd/.style={circle}} \tikzset{pre/.style={ <-,shorten <=2pt,shorten >=2pt, >=stealth', semithick}} % to avoid using every time dollars for math mode \tikzset{math mode/.style={% execute at begin node=$,%
execute at end node=$,% } } \node[place] (first) {}; % using a scope to not apply the new math mode definition to all nodes % as it might not be the desired behaviour \begin{scope}[every node/.style={math mode}] \node[place] (second) [right=of first] {} edge [pre,bend right] node [above] {a} (first) edge [pre,bend left] node [below] {b} (first); \node[place] (third) [right=of second] {} edge [pre] node [above] {c} (second); \node[surd] (surd) [right=of third] {\Large\surd} edge [pre] node [above] {d} (third); \end{scope} \end{tikzpicture} \end{center} \end{frame} \end{document}  A complete example without the style math mode: \documentclass{beamer} \usepackage{lmodern} \usepackage{tikz} \usetikzlibrary{arrows,positioning} \usefonttheme[onlymath]{serif} \begin{document} \begin{frame}{title} Some text in sans serif font. Math, like: $$x+y=100$$ is rendered in serif font. \begin{center} \begin{tikzpicture}[node distance=2cm,inner sep=2pt,minimum size=0.5mm, bend angle=45] \tikzset{place/.style={circle,draw=black,fill=black,thick}} \tikzset{surd/.style={circle}} \tikzset{pre/.style={ <-,shorten <=2pt,shorten >=2pt, >=stealth', semithick}} %\tikzset{every node/.append style={font=\normalsize\itshape}} %useless in this case \node[place] (first) {}; \node[place] (second) [right=of first] {} edge [pre,bend right] node [above] {$a$} (first) edge [pre,bend left] node [below] {$b$} (first); \node[place] (third) [right=of second] {} edge [pre] node [above] {$c$} (second); \node[surd] (surd) [right=of third] {\Large$\surd$} edge [pre] node [above] {$d$} (third); \end{tikzpicture} \end{center} \end{frame} \end{document}  The result: - A note: to go in new line you don't need 220 spaces (on average) at the end of the line. – Claudio Fiandrino Sep 6 '13 at 7:01 One question: is \tikzstyle = [something/.style = ... ] ? – tdi Sep 6 '13 at 7:02 What about non beamer environments ? I might need to create an article from this presentation and reuse there my pictures. Is this similar? – tdi Sep 6 '13 at 7:03 And what if I ommit$a\$ and write only a ? Will it also work ? (sorry for so many questions) – tdi Sep 6 '13 at 7:05
tikzstyle is obsolete, as per my previous comment; second: for the article you don't have any problems in copy and paste the pictures' code: they will use automatically serif font (unless you specified something different, but that's not the default behaviour). – Claudio Fiandrino Sep 6 '13 at 7:06