我有一个简单的状态转换图,我想在 latex 中渲染它,最好使用常规 mathmode 标记。箭头显示状态之间转换的概率。
\underbrace{\boxed{A}}_{1/4}
\;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\underbrace{\boxed{B}}_{1/2}
\;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\underbrace{\boxed{C}}_{1}
从左到右的箭头没问题,但我希望使用弯曲箭头而不是下括号来显示保持该状态的概率。因此,处于 A 并停留在 A 的概率为 1/4,处于 B 并停留在 B 的概率为 1/2,依此类推。我想用位于状态下方(或上方)的箭头来显示这一点。这可能吗?
编辑:这是我的示意图。
然而,沃纳在他的评论中做了一个更好的模型。
我更喜欢这样的东西,但也乐意接受更粗糙的东西!
答案1
以下是仅使用数学模型的一个选项:
\documentclass{article}
\usepackage{amsmath,amssymb}% http://ctan.org/pkg/{amsmath,amssymb}
\begin{document}
\[
\underbrace{\boxed{A}}_{1/4}
\;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\underbrace{\boxed{B}}_{1/2}
\;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\underbrace{\boxed{C}}_{1}
\]
\[
\mathop{\boxed{A}}_{\substack{\circlearrowleft\\1/4}}
\;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\mathop{\boxed{B}}_{\substack{\circlearrowleft\\1/2}}
\;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\mathop{\boxed{C}}_{\substack{\circlearrowleft\\1}}
\]
\end{document}
也许你也可以自己定义一些与马尔可夫相关的宏:
\documentclass{article}
\usepackage{amsmath,amssymb}% http://ctan.org/pkg/{amsmath,amssymb}
\makeatletter
\def\ifemptyarg#1{% http://tex.stackexchange.com/a/58638/5764
\if\relax\detokenize{#1}\relax % H. Oberdiek
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
\makeatother
\newcommand{\probstyle}{\scriptscriptstyle}
\newcommand{\State}[1]{\mathop{\boxed{#1}}}
\newcommand{\stayprob}[1]{\substack{\circlearrowleft\\\probstyle#1}}
\newcommand{\trans}[2]{%
\edef\dirarrow{\ifemptyarg{#1}{\rightarrow}{\ifemptyarg{#2}{\leftarrow}{\rightleftarrows}}}%
\;\mathrel{\mathop{\dirarrow}^{\probstyle#1}_{\probstyle#2}}\;}
\begin{document}
\[
\State{A}_{\stayprob{1/4}}
\trans{3/4}{1/4}
\State{B}_{\stayprob{1/2}}
\trans{1/4}{}
\State{C}_{\stayprob{1}}
\]
\end{document}
上面也用于\probstyle
设置中的概率值\scriptscriptstyle
。
答案2
我知道你说过理想情况下你想使用常规的数学模式标记,但如果你愿意使用TikZ
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
state/.style={
draw,
minimum size=0.7cm,
},
ar/.style={
->,shorten >=3pt,shorten <=3pt
},
every loop/.style={ar,<->}
]
\node[state] (a) {$A$}
edge [in=290,out=250,loop] node[below] {$\frac{1}{4}$} ();
\node[state] at (1.5,0) (b) {$B$}
edge [in=290,out=250,loop] node[below] {$\frac{1}{2}$} ();
\node[state] at (3,0) (c) {$C$}
edge [in=290,out=250,loop] node[below] {$1$} ();
\draw[ar]
([yshift=2pt]a.east) -- node[auto] {$\frac{3}{4}$} ([yshift=2pt]b.west|-a);
\draw[ar]
([yshift=-2pt]b.west) -- node[auto] {$\frac{1}{4}$} ([yshift=-2pt]a.east|-b);
\draw[ar]
(b) -- node[auto] {$\frac{1}{4}$} (c);
\end{tikzpicture}
\end{document}
也许更短tikz-cd
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={draw,minimum size=0.7cm}}]
A
\arrow[yshift=2pt]{r}{\frac{3}{4}}
\arrow[in=290,out=250,loop]{}[below]{\frac{3}{4}}
&
B
\arrow[yshift=-2pt]{l}{\frac{1}{4}}
\arrow{r}{\frac{1}{4}}
\arrow[in=290,out=250,loop]{}[below]{\frac{1}{2}}
&
C
\arrow[in=290,out=250,loop]{}[below]{1}
\end{tikzcd}
\end{document}
答案3
该解决方案使用\downtouparrow
包mathabx
,但它不加载包,因为它改变了很多其他的东西。
还可以使用可伸缩的箭/鱼叉。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{chemarr}
% from package mathabx:
\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
<5> <6> <7> <8> <9> <10> gen * mathb
<10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
}{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}
\DeclareFontSubstitution{U}{mathb}{m}{n}
\DeclareMathSymbol{\downtouparrow}{3}{mathb}{"FF}
\newcommand*{\underarrow}[2]{%
\underset{%
\textstyle
\underset{#2}{\downtouparrow}%
}{#1}%
}
\begin{document}
\[
\underarrow{\boxed{A}}{1/4}
% \;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\xrightleftharpoons[1/4]{3/4}
\underarrow{\boxed{B}}{1/2}
% \;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\xrightarrow{1/4}
\underarrow{\boxed{C}}{1}
\]
\end{document}
变体\curvearrowleft
的箭头尖端\curvearrowleft
确实与其他箭头更贴合。但需要旋转(或镜像):
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{chemarr}
\usepackage{graphicx}
\newcommand*{\underarrow}[2]{%
\underset{%
\textstyle
\underset{#2}{\rotatebox[origin=c]{180}{$\curvearrowleft$}}%
}{#1}%
}
\begin{document}
\[
\underarrow{\boxed{A}}{1/4}
% \;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\xrightleftharpoons[1/4]{3/4}
\underarrow{\boxed{B}}{1/2}
% \;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\xrightarrow{1/4}
\underarrow{\boxed{C}}{1}
\]
\end{document}
答案4
沃纳 (Werner) 答案的一种变体,带有不同的箭头:
\documentclass{article}
\usepackage{mathtools,amssymb,graphicx}
\newcommand{\myarrow}{\scalebox{1.2}[-2]{$\mathclap{\curvearrowleft}\mkern2.2mu
\mathclap{\curvearrowright}$}}
\begin{document}
\[
\underbrace{\boxed{A}}_{1/4}
\;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\underbrace{\boxed{B}}_{1/2}
\;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\underbrace{\boxed{C}}_{1}
\]
\[
\mathop{\boxed{A}}_{\substack{\myarrow\\1/4}}
\;\mathrel{\mathop{\rightleftarrows}^{3/4}_{1/4}}\;
\mathop{\boxed{B}}_{\substack{\myarrow\\1/2}}
\;\mathrel{\mathop{\rightarrow}^{1/4}}\;
\mathop{\boxed{C}}_{\substack{\myarrow\\1}}
\]
\end{document}