# How to draw slanting arrows between columns of a table?

I'd like to draw some simple slanting arrows between cells in a table. The two cells can be in almost any position in the table.

For example given this table:

How can I modify it to obtain:

Another example with also vertical arrows:

Ideally I'd like to avoid using Tikz, since using tabular is pretty straightforward to draw this kind of diagrams, but if nothing else can be done then I'll accept a Tikz solution.

The MWE code for the table:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{figure}[H]
\begin{tabular}{cccccccc}
((\textbf{N}   & $\Rightarrow$ & \textbf{N}) & $\Rightarrow$ & \textbf{N})& $\Longrightarrow$ & \textbf{N} &     \\
&               &             &               &            &                   &     $q$      & $O$ \\
&               &             &               &    $q$     &                   &              & $P$ \\
&               &     $q$     &               &            &                   &              & $O$ \\
&               &             &               &    $q$     &                   &              & $P$ \\
&               &     $q$     &               &            &                   &              & $O$ \\
$q$     &               &             &               &            &                   &              & $P$ \\
&               &             &    $\vdots$   &            &                   &              &     \\
\end{tabular}
\end{figure}

\end{document}


Use \xymatrix from the xypic package (for a proper introduction to its use, see the excellent XY-pic User’s Guide). The \ar[d] command typesets arrows in the direction specified as optional argument, so \ar[r] moves one cell to the right, \ar[ur] moves one up and one right etc. You can use \ar@2{->}[r] for double arrows and \ar@2/^/[u] and \ar@2/_/[u] for curved arrows.

The first version uses code very similar to your table, the second one replaces all the \Rightarrows by xy's arrows and the third one showcases the use of slanted arrows.

\documentclass{article}

\usepackage[all]{xy}

\begin{document}
\xymatrix@=2pt{
((\textbf{N} & \Rightarrow & \textbf{N}) & \Rightarrow & \textbf{N})  & \Longrightarrow & \textbf{N} &  \\
&             &             &             &              &                 &    q       & O\\
&             &             &             &  q \ar[urr]  &                 &            & P\\
&             & q \ar[urr]  &             &              &                 &            & O\\
&             &             &             & q \ar[uuurr] &                 &            & P\\
&             &  q \ar[urr] &             &              &                 &            & O\\
q \ar[urr] &             &             &             &              &                 &            & P\\
&             &             &    \vdots   &              &                 &            & }

\xymatrix@R=2pt{
((\textbf{N} \ar@2{->}[r] & \textbf{N}) \ar@2{->}[r] & \textbf{N}) \ar@2{->}[r] & \textbf{N} &  \\
&                          &                          &     q      & O\\
&                          &        q \ar[ur]         &            & P\\
&       q \ar[ur]          &                          &            & O\\
&                          &       q \ar[uuur]        &            & P\\
&       q \ar[ur]          &                          &            & O\\
q \ar[ur]       &                          &                          &            & P\\
&        \vdots            &                          &            & }

\xymatrix@R=2pt{
(\textbf{N} \ar@2{->}[r] & \textbf{N} \ar@2{->}[r] & \textbf{N}) \ar@2{->}[r] & \textbf{N} \\
&                         &                          &     q      \\
&                         &        q \ar[ur]         &            \\
q \ar[urr]      &                         &                          &            \\
\ar@/^1pc/[u]0   &       q \ar[uur]        &                          &            \\
&      \ar@/^1pc/[u]1     &                          &            \\
&                         &          n\ar[uuuu]      &            \\
&                         &                          & n\ar[uuuuuu]}
\end{document}


## EDIT

Centering xydiagrams is easy enough, you can either wrap the xymatrix in a display math environment with $.....$ (alternative \begin{equation*}...\end{equation*} or whatever fits your needs) or you can wrap it in \centerline{...}.

\documentclass{article}

\usepackage[all]{xy}

\begin{document}
\begin{figure}
\centerline{\xymatrix@R=2pt{
((\textbf{N} \ar@2{->}[r] & \textbf{N}) \ar@2{->}[r] & \textbf{N}) \ar@2{->}[r] & \textbf{N} &   \\
&                          &                          &     q      & O \\
&                          &        q \ar[ur]         &            & P \\
&       q \ar[ur]          &                          &            & O \\
&                          &       q \ar[uuur]        &            & P \\
&       q \ar[ur]          &                          &            & O \\
q \ar[ur]       &                          &                          &            & P \\
&        \vdots            &                          &            & }}
\caption{A very interesting diagram with \texttt{centerline}}
\end{figure}

\begin{figure}
$\xymatrix@R=2pt{ (\textbf{N} \ar@2{->}[r] & \textbf{N} \ar@2{->}[r] & \textbf{N}) \ar@2{->}[r] & \textbf{N} \\ & & & q \\ & & q \ar[ur] & \\ q \ar[urr] & & & \\ \ar@/^1pc/[u]0 & q \ar[uur] & & \\ & \ar@/^1pc/[u]1 & & \\ & & n\ar[uuuu] & \\ & & & n\ar[uuuuuu]}$
\caption{A very interesting diagram with displaymath}
\end{figure}
\end{document}


For different length arrows you can use \Rightarrow and \Longrightarrow see the first example. xypic's xymatrix draws arrows between cells in a matrix, so to get arrows of different length, you will needs cells that are further apart (this is achieved by empty cells) this will move around the rest of the diagram though.

• I have a problem with this solution: if I put the xymatrix inside a figure environment the \centering doesn't have any effect. The caption is placed at the center, but the diagram is flushed left. Is this a known issue? – Bakuriu Sep 13 '13 at 8:08
• Another request if possible: how can I draw arrows of different lenghts? In your last two examples I'd like the double arrows inside the parenthesis to be shorter then the one outside, without changing the spacing between other elements of the diagram, if possible. – Bakuriu Sep 13 '13 at 8:24
• @Bakuriu xymatrix is originally a package for commutative diagrams; if you want something fancier, you might want to have a look at TikZ and PGF. You will then have to trade in the "comfort" of xymatrix' almost "table"-like structure for something slightly more complicated. – moewe Sep 13 '13 at 9:48