# How to draw a cyclic sequence in latex

  $$a_0 \to a_1 \to a_2 \to ....... \to a_k$$


Right now, I want to draw a curved directed arrow that goes from $a_k$ to $a_0$

Is there any way to do that ?

Thanks

There is tikzmark library for this. You can make one handmade macro yourself too.

\documentclass{article}
\usepackage{tikz}
\newcommand{\tikzmark}[3][]{\tikz[remember picture,baseline] \node [inner xsep=0pt,anchor=base,#1](#2) {#3};}

\begin{document}
$\tikzmark{a}{a_0} \to a_1 \to a_2 \to \dots \to \tikzmark{b}{a_k}$
\begin{tikzpicture}[remember picture,overlay]
\draw[->] (a.north east) to[bend left] (b.north west);
\end{tikzpicture}
\end{document}


To make it cyclic, some thing like this:

\documentclass{article}
\usepackage{tikz}
\newcommand{\tikzmark}[3][]{\tikz[remember picture,baseline] \node [inner xsep=0pt,anchor=base,#1](#2) {#3};}

\begin{document}
$\tikzmark{a}{a_0} \to a_1 \to a_2 \to \dots \to \tikzmark{b}{a_k}$
\begin{tikzpicture}[remember picture,overlay]
\draw[->,rounded corners=1ex] (b.east) -| ++(2ex,2ex)  to[bend right,looseness=1] ([shift={(-2ex,2ex)}]a.west) |- (a.west);
\end{tikzpicture}
\end{document}


• Is thick necessary? Actually, I think it's wrong. Also the random dots should be \dots – egreg Apr 8 '15 at 8:10
• @egreg Right, changed, :-) – user11232 Apr 8 '15 at 9:50
• Can one modify this so the arrow goes from $a_k$ starts of to the right, then loops around and approaches $a_0$ from the top or left? (So as to make the diagram appear more cyclic. BTW the OP asked for the arrow in the other direction--from mark $b$ to $a$.) – Kimball Apr 8 '15 at 11:39
• @Kimball: not a problem. – user11232 Apr 8 '15 at 12:40

The following solution with TikZ works without \tikzmark and additional LaTeX run for remembering positions. The arrow head of the curved arrow matches the default appearance of LaTeX's \rightarrow or its synonym \to. Also the start of the error uses a round line cap. Parameter looseness is used to flatten the curve a bit to reduce the vertical space requirements of the curved arrow:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}
\usetikzlibrary{topaths}

\begin{document}
$$\begin{tikzpicture}[ baseline=(a0.base), inner sep=0pt, line cap=round, >={Computer Modern Rightarrow[bend]}, ] \node (a0) {a_0}; \node[anchor=base west] (a1) at (a0.base east) {{}\to a_1 \to a_2 \to \dots \to{}}; \node[anchor=base west] (ak) at (a1.base east) {a_k}; \draw[ ->, transform canvas={yshift=.3em}, ] (ak) to[bend right, looseness=.6] (a0); \end{tikzpicture}$$
\end{document}


Remarks:

• Do not use  for displayed equations in LaTeX, see Which command should I use for displayed equations?

• inner sep=0pt avoids additional white margins around the nodes. yshift is used to move the curved arrow a bit to the top to get more distance between the arrow start and end to the corresponding math symbols. An alternative approach would be the use of options shorten < and shorten >.

• The empty {} in math mode as in {} \to a_1 make an empty math atom for the proper spacing around \to.

Second solution shows how to do this without usage of TikZ. Only pdfTeX primitives are expected.

{\lccode\?=\p \lccode\!=\t  \lowercase{\gdef\ignorept#1?!{#1}}}
\def\usedim#1 {\expandafter\ignorept\the#1 \space}

\def\cyclicseq#1{\setbox0=\hbox{\kern-.7em$#1$\kern-.7em}%
\dimen0=.3\wd0 \dimen1=.7\wd0
\leavevmode \kern.7em
\pdfsave\pdfsetmatrix{.9397 .342 -.342 .9397}\raise4pt\rlap{$\prec$}\pdfrestore
\pdfliteral{q .9963 0 0 .9963 0 7 cm .4 w 0 0 m
\usedim\dimen0 10 \usedim\dimen1 10 \usedim\wd0 0 c S Q}%
\vbox to15pt{}\box0 \kern.7em
}

Text $\cyclicseq{a_0 \to a_1 \to a_2 \to \ldots \to a_k}$ text.