Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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} 
share|improve this question
1  
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
add comment

1 Answer

up vote 5 down vote accepted

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

share|improve this answer
    
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
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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