Today, I will show how to draw a sequence in Latex using the TIKZ package. A sequence is an ordered list of symbols. I often draw sequences for my research paper about sequential pattern mining or episode mining. To draw a sequence, I first import the TIKZ package by adding this line in the section for packages:
\usepackage{tikz}
Then, to draw a sequence in a figure, I use this code:
\begin{figure}[ht] \centering \begin{tikzpicture} %timeline \draw (-0.4,0) -- (7,0); % The labels \node[] at (-1,0.6) {\textbf{event sets}}; \node[] at (-1,-0.6) {\textbf{timestamps}}; % first element \draw (0.4,-0.2) -- (0.4,0.3); \node[] at (0.4,0.6) {${a,c}$}; \node[] at (0.4,-0.6) {$1$}; % second element \draw (1.2,-0.2) -- (1.2,0.3); \node[] at (1.2,0.6) {${a}$}; \node[] at (1.2,-0.6) {$2$}; % third element \draw (2,-0.2) -- (2,0.3); \node[] at (2,0.6) {${a,b}$}; \node[] at (2,-0.6) {$3$}; % next element \draw (2.8,-0.2) -- (2.8,0.3); \node[] at (2.8,0.6) {${a}$}; \node[] at (2.8,-0.6) {$6$}; % next element \draw (3.6,-0.2) -- (3.6,0.3); \node[] at (3.6,0.6) {${a,b}$}; \node[] at (3.6,-0.6) {$7$}; % next element \draw (4.4,-0.2) -- (4.4,0.3); \node[] at (4.4,0.6) {${c}$}; \node[] at (4.4,-0.6) {$8$}; % next element \draw (5.2,-0.2) -- (5.2,0.3); \node[] at (5.2,0.6) {${b}$}; \node[] at (5.2,-0.6) {$9$}; % next element \draw (6,-0.2) -- (6,0.3); \node[] at (6,0.6) {${d}$}; \node[] at (6,-0.6) {$11$}; % The arrow \draw (6.8,-0.13) -- (7,0); \draw (6.8,0.13) -- (7,0); \end{tikzpicture} \caption{A complex event sequence with eight event sets} \label{CES} \end{figure}
The result looks like this:
Another example:
\begin{figure} \centering %%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{tikzpicture}[xscale=8] \draw[-][draw=black, very thick] (-0.1,0) -- (.5,0); \draw[->][draw=black, very thick] (.5,0) -- (1.1,0); %\draw [thick] (0,-.1) node[below]{0} -- (0,0.1); \draw [thick] (0.25,-.1) node[below]{$t-\frac{\gamma-1}{2}$} -- (0.25,0.1); \draw [thick] (0,-.1) node[below]{$t-\frac{\lambda\times\gamma-1}{2}$} -- (0,0.1); %%%% WINDOW A \draw [thick, dashed] (0.25,0) -- (0.25,.5) -- (.5,.5) node[above]{ \scriptsize a) short term window (of length $\gamma$) } -- (0.75,.5) -- (0.75,0) ; \draw [thick, dashed] (0,0) -- (0,1) -- (.5,1) node[above]{ \scriptsize b) long term window (of length $\lambda \times \gamma $) } -- (1,1) -- (1,0) ; \draw [thick] (0.5,-.1) node[below]{$t$} -- (0.5,0.1); \draw [thick] (0.75,-.1) node[below]{$t+\frac{\gamma-1}{2}$} -- (0.75,0.1); \draw [thick] (1,-.1) node[below]{$t+\frac{\lambda\times\gamma-1}{2}$} -- (1,0.1); %\draw [thick] (1,-.1) node[below]{1} -- (1,0.1); \end{tikzpicture} %\caption{The windows for calculating the a) short term and b) long term moving average utility for a timestamp $t$.} \end{figure}
The results is:

You could improve upon this using other options in Tikz to add colors, etc. Besides, as a bonus, if I want to write a sequence using Latex math notation in a paragraph, I write like this:
$S=\langle ({a,c}, $ $ 1),$ $
({a},2),$ $({a,b},3),$ $({a},6),$ $({a,b},7),$ $({c},8),$ $({b},9),$ $({d},{11}) \rangle$
The result will be:

Hope this will be useful for your Latex documents
—
Philippe Fournier-Viger is a distinguished professor working in China and founder of the SPMF open source data mining software.