# How can I get curly arrow underneath a state in a state transition diagram

I have a simple state transition diagram that I'd like to render in latex ideally using regular mathmode markup. The arrows show the probability of going between states. \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}


The left-to-right arrows are fine, but I'd like curly arrows rather than the underbraces to show the probability of remaining in the state. So there is a 1/4 probability of being in A and staying in A, a 1/2 probability of being in B and staying in B and so on. And I'd like to show this with an arrow below (or above) the state. Is this possible?

Edit: here's my schematic. however Werner has done a much nicer mock-up in his comment. I'd prefer something like this but would be happy to settle for something cruder!

• I have some difficulty imagining the shape and position of those curly arrows. Can you please describe the desired shape in more detail or post an image (hand drawn) of the desired output? – Gonzalo Medina Mar 1 '14 at 0:32
• What about something like this? – Werner Mar 1 '14 at 0:38
• @Werner yes, exactly, thankyou, I've stolen your image and edited into my question :) – TooTone Mar 1 '14 at 0:42
• @GonzaloMedina FYI the question is amended – TooTone Mar 1 '14 at 0:43

Here is one option using only math mockup: \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}


Perhaps you can also define yourself some Markov-related macros: \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}{\mathop{\boxed{#1}}}
\newcommand{\stayprob}{\substack{\circlearrowleft\\\probstyle#1}}
\newcommand{\trans}{%
\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}


The above also uses \probstyle to set the probability values in \scriptscriptstyle.

• thankyou! that looks good, the only thing I might want is to make the curly arrows a bit larger (I guess they're smaller because they're subscripted). I found I could use \mathlarger from the relsize package unless you think there's something better? – TooTone Mar 1 '14 at 0:59

I know you said that ideally you wanted to use regular mathmode markup, but in case you are willing to use 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} And perhaps shorter with 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} • thankyou that's pretty cool. I dropped it straight into a document I'm working on. Ideally I'm hoping to find something I can do in the language I already know, if possible (because I find it quite difficult to remember the details of the 4 or 5 languages I use at the moment and ideally don't want to add another). But if not this will be another handy tool in the toolbox. – TooTone Mar 1 '14 at 0:51

This solution uses \downtouparrow of package mathabx, but it does not load the package, because it changes lots of other things.

Also extensible arrows/harpoons are used.

\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}{%
\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} ## Variant with \curvearrowleft

The arrow tip of \curvearrowleft does fit better to the other arrows. But it needs to be rotated (or mirrored):

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{chemarr}
\usepackage{graphicx}

\newcommand*{\underarrow}{%
\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} A variation of Werner's answer with a different arrow:

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