我需要用一些包含数学符号的文本来装饰路径。我跟着这个例子,只要我只包含文本,它就可以正常工作。以下是 MWE(与替换为\def\myshift
的示例相比有细微变化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}
但是,只要我替换a
(\alpha
作为示例),MWE 就不会再编译。它似乎挂起了,当我用 ctrl-C 中断它时,我得到:
! Interruption.
<to be read again>
\let
l.12 ...\alpha$}}}] (One) to [bend left=45] (Two);
(我在跑pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019)
。)
答案1
将宏括起来。为什么?因为在手册 v3.1.5 第 659 页中说
一旦我添加大括号,就没有任何问题了。
\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}
答案2
不完全是答案... 在我的数学老师的软件包列表中,这个软件包一直被称为tkz-graph
。您需要了解 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}
只需一行代码即可获得下图(如果您需要概率图或图论示例)
\documentclass[border=.25cm]{standalone}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
\grProb{A}{B}{NO}{SO}{WE}{EA}
\end{tikzpicture}
\end{document}