# Draw a sequence of circles in a node with TiKz

I am trying to draw a figure similar to this one from Warrington, G. S. (2005). Juggling probabilities. The American Mathematical Monthly, 112(2), 105-118, using TiKz package in LaTeX

I know how to create rectangles as nodes, and connect nodes with the arrows. However, I can't find how to draw white and black circles inside nodes. Here some code that I have:

\begin{figure}
\begin{center}
\begin{tikzpicture}[scale=2.5,->,>=stealth',shorten >=1pt,auto,inner sep=2pt,semithick,bend angle=20]
\node[rectangle,draw] (A) at (0,0)  {Rectangle};
\node[rectangle,draw] (B) at (1,0)  {Rectangle};
\node[rectangle,draw] (C) at (2,0)  {Rectangle};
\node[rectangle,draw] (D) at (3,0)  {Rectangle};
\node[rectangle,draw] (E) at (4,0)  {Rectangle};
\path (A) edge [bend right,looseness=0.9] node[swap] {$1$}            (B)
(B) edge [bend right,looseness=0.9] node[swap] {$\dfrac{1}{4}$} (A)
edge [bend right,looseness=0.9] node[swap] {$\dfrac{3}{4}$} (C)
(C) edge [bend right,looseness=0.9] node[swap] {$\dfrac{1}{2}$} (B)
edge [bend right,looseness=0.9] node[swap] {$\dfrac{1}{2}$} (D)
(D) edge [bend right,looseness=0.9] node[swap] {$\dfrac{3}{4}$} (C)
edge [bend right,looseness=0.9] node[swap] {$\dfrac{1}{4}$} (E)
(E) edge [bend right,looseness=0.9] node[swap] {$1$}            (D);
\end{tikzpicture}
\caption{Transition}
\end{center}
\end{figure}

• Welcome to TeX.SE!. It would be helpful if you add to your question some work you have done so far. – Cragfelt Nov 16 '17 at 19:05
• Inside a node you can insert TeX commands, eg. $\bullet\circ$. – Sigur Nov 16 '17 at 20:46

Here a possible solution with a little tabular as node text:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\newcolumntype{C}{>{$}c<{$}}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\tikzset{
mynode/.style ={
draw,
rectangle,
scale=.5
},
mydescr/.style={
swap,
text height=3.6ex,
text depth=2ex
},
}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[->,>=Stealth,shorten >=1pt,auto,inner sep=2pt,semithick,bend angle=20]
\node[mynode] (A) {\begin{tabular}{*4C}
\smile & \bullet & \bullet & \bullet \\
\end{tabular}};
\node[mynode, right=of A] (B) {\begin{tabular}{*4C}
\bullet & \smile & \bullet & \bullet \\
\end{tabular}};
\node[mynode, right=of B] (C) {\begin{tabular}{*4C}
\bullet & \bullet & \smile & \bullet \\
\end{tabular}};
\node[mynode, right=of C] (D) {\begin{tabular}{*4C}
\bullet & \bullet & \bullet & \smile \\
\end{tabular}};
\node[mynode, right=of D] (E)  {\begin{tabular}{*4C}
\smile & \bullet & \bullet & \bullet \\
\end{tabular}};
\path (A) edge [bend right,looseness=0.9] node[mydescr] {$1$}            (B)
(B) edge [bend right,looseness=0.9] node[mydescr] {$\dfrac{1}{4}$} (A)
edge [bend right,looseness=0.9] node[mydescr] {$\dfrac{3}{4}$} (C)
(C) edge [bend right,looseness=0.9] node[mydescr] {$\dfrac{1}{2}$} (B)
edge [bend right,looseness=0.9] node[mydescr] {$\dfrac{1}{2}$} (D)
(D) edge [bend right,looseness=0.9] node[mydescr] {$\dfrac{3}{4}$} (C)
edge [bend right,looseness=0.9] node[mydescr] {$\dfrac{1}{4}$} (E)
(E) edge [bend right,looseness=0.9] node[mydescr] {$1$}            (D);
\end{tikzpicture}
\caption{Transition}
\end{figure}
\end{document}


Another method, using a \pic. The argument to the pic defines which of the four symbols is not drawn as a bullet.

I also simplified the arrow drawing a bit. Instead of specifying bend right,looseness=1 for every edge, and swap for every node, I add those options once, to the \path. And instead of node {foo}, I added the quotes library, which lets you use the shorthand edge["foo"].

\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}
\usetikzlibrary{quotes} % to use the "<label>" syntax for to-paths, e.g. (a) to["foo"] (b)
\tikzset{
juggle/.pic={
\foreach \x in {1,...,4}
{
\ifnum \x=#1
\draw (\x cm/3-4pt,0) to[bend right] ++(8pt,0);
\else
\fi
}
\node[draw,above right,name=-outline,minimum width=1.6cm,minimum height=5mm] at (0,-0.25) {};
}
}

\begin{document}
\begin{tikzpicture}[
arr/.style={
-stealth,
shorten >=3pt,
shorten <=3pt,
swap
}
]
\pic (A) at (0,0) {juggle=1};
\pic (B) at (2,0) {juggle=2};
\pic (C) at (4,0) {juggle=3};
\pic (D) at (6,0) {juggle=4};
\pic (E) at (8,0) {juggle=1};

\path [swap,-stealth,bend right=45] % set looseness here as well, if needed
(A-outline) edge ["$1$"]            (B-outline)
(B-outline) edge ["$\dfrac{1}{4}$"] (A-outline)
edge ["$\dfrac{3}{4}$"] (C-outline)
(C-outline) edge ["$\dfrac{1}{2}$"] (B-outline)
edge ["$\dfrac{1}{2}$"] (D-outline)
(D-outline) edge ["$\dfrac{3}{4}$"] (C-outline)
edge ["$\dfrac{1}{4}$"] (E-outline)
(E-outline) edge ["$1$"]            (D-outline);
\end{tikzpicture}
\end{document}


\documentclass[border=2pt]{standalone}
\usepackage{tikz,amsmath}
\usetikzlibrary{quotes} % to use the "<label>" syntax for to-paths, e.g. (a) to["foo"] (b)
\tikzset{
juggle/.pic={
\foreach \x in {1,...,4}
{
\ifnum \x=#1
\draw (\x cm/2-4pt,0) to[bend right] ++(8pt,0);
\else
\fi
}
\node[draw,above right,name=-outline,minimum width=2cm,minimum height=5mm] at (0.25,-0.25) {};
}
}

\begin{document}
\begin{tikzpicture}[
arr/.style={
-stealth,
shorten >=3pt,
shorten <=3pt,
swap
}
]

\pic (A) at (0,0)    {juggle=3};
\pic (B) at (4,0)    {juggle=1};
\pic (C) at (2,1.5)  {juggle=4};
\pic (D) at (2,-1.5) {juggle=2};

\draw [arr] (D-outline) to["1"] (C-outline);
\draw [arr] (A-outline) to["4"] (D-outline);
\draw [arr] (D-outline) to["4"] (B-outline);
\draw [arr] (B-outline) to["0"] (C-outline);
\draw [arr] (A-outline) to["2"] (C-outline);
\draw [arr] (C-outline.south west) to["4"] (A-outline.140);
\draw (C-outline) edge[every loop/.append style={-stealth},loop above,"3"] (C-outline);
\end{tikzpicture}
\end{document}