5

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

This is what I want enter image description here,

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} 
3

1 Answer 1

6

With the Beamer class you may want to use:

\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:
\begin{equation}
x+y=100
\end{equation}
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:
\begin{equation}
x+y=100
\end{equation}
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:

enter image description here

8
  • A note: to go in new line you don't need 220 spaces (on average) at the end of the line. Sep 6, 2013 at 7:01
  • One question: is \tikzstyle = [something/.style = ... ] ?
    – Darek
    Sep 6, 2013 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?
    – Darek
    Sep 6, 2013 at 7:03
  • And what if I ommit $a$ and write only a ? Will it also work ? (sorry for so many questions)
    – Darek
    Sep 6, 2013 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). Sep 6, 2013 at 7:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .