使用数学字体作为 TikZ 箭头标签

使用数学字体作为 TikZ 箭头标签

我正在尝试使箭头标签看起来像是在数学模式下编写的。这就是我所拥有的: enter image description here

这就是我要的enter image description here

我尝试使用不同的字体,但没有成功。这是我的代码:

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

答案1

对于 Beamer 类,你可能需要使用:

\usefonttheme[onlymath]{serif}

只用衬线字体显示数学。如果不想每次$进入数学模式时都输入,可以创建一个样式:

\tikzset{math mode/.style={%
    execute at begin node=$,%
    execute at end node=$,%
  }
} 

然后,通过对所有节点进行分组scope

\begin{scope}[every node/.style={math mode}]
...
\end{scope}

该样式将被“本地”应用。

样式活动的示例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}} 
  % 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}

没有样式的完整示例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}

结果:

enter image description here

相关内容