# Curvy arrows between two tables (with tikz?)

I try to connect two arbitrary tables with arrows. The code example below should demonstrate how: say we want to connect the "1" in A with the "5" in B, the "2" in A with the "7" in B and so on. My wish would be to have "curvy" arrows (as far as i know the tikz packages provides them) and not "straight" arrows.

Is it even possible to combine "ordinary" tabular elements with tikz nodes oder drawings? If yes, how? If not, is there a pure tikz way to solve that problem? Thanks for any advices or hints!

\documentclass[12pt,a4paper,twoside]{scrartcl}
\begin{document}
\begin{center}

\begin{tabular}{c c c c c c}
$A$ & 1 & 2 & 3 & 4 &
\end{tabular}

\vspace{15mm}

\begin{tabular}{c c c c c c c c c c }
$B$ & \fbox{5} & 6 & \fbox{7} & 8 & \fbox{9} & 10 & \fbox{11} & 12 &
\end{tabular}

\end{center}
\end{document}

-

Do you mean something like this:

## Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand*{\DrawArrow}[3][]{%
% #1 = draw options
% #2 = left point
% #3 = right point
\begin{tikzpicture}[overlay,remember picture]
\draw [very thick, -stealth, #1] ($(#2)+(0.25em,-0.3ex)$) to ($(#3)+(0.25em,2.5ex)$);
\end{tikzpicture}%
}%

\begin{document}
\begin{center}

\begin{tabular}{c c c c c c}
$A$ & \tikzmark{topA}1 & \tikzmark{topB}2 & \tikzmark{topC}3 & \tikzmark{topD}4 &
\end{tabular}

\vspace{15mm}

\begin{tabular}{c c c c c c c c c c }
$B$ & \fbox{\tikzmark{bottomA}5} & 6 & \fbox{\tikzmark{bottomB}7} & 8 & \fbox{\tikzmark{bottomC}9} & 10 & \fbox{\tikzmark{bottomD}11} & 12 &
\end{tabular}
\DrawArrow[red,   out=-90, in=90]{topA}{bottomA}
\DrawArrow[olive, out=-90, in=90]{topB}{bottomB}
\DrawArrow[blue,  out=-90, in=90]{topC}{bottomC}
\DrawArrow[brown, out=-90, in=90]{topD}{bottomD}
\end{center}
\end{document}

-
Wow! That's exactly my desired representation. Thank you very much for the quick response and the understandable code style! –  bobb_the_builder Mar 22 '13 at 22:05
Wait... I wasn't done... Solution now updated with a better macro interface. –  Peter Grill Mar 22 '13 at 22:11
The vertical line passing through the center of one row is not aligned with that of the other row. In other words, 2 and 8 should be in the same column. :D –  In PSTricks we trust Mar 22 '13 at 22:36
@Karl'sstudents: Not sure I understand. I am just connecting existing text, not adjusting it. The positions can be adjusted as needed. –  Peter Grill Mar 22 '13 at 22:40
I meant, 2 and 8 should be in the same column. In other words, 8 should be right below 2 such that 3 and 9 are connected with a straight line. By the way, it is not crucial issue. :-) –  In PSTricks we trust Mar 22 '13 at 22:44

With PSTricks.

\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pst-node}
\psset
{
mnode=r,
rowsep=2cm,
colsep=0.5cm,
}

\def\c{[mnode=circle] }

\begin{document}
\offinterlineskip
\begin{psmatrix}
& & A & 1 & 2 & 3 & 4\\
B & \c 5 & 6 & \c 7 & 8 & \c 9 & 10 & \c 11 & 12
\foreach \i/\j in {4/2,5/4,6/6,7/8}
{\nccurve[angleA=-90,angleB=90,nodesep=3pt]{->}{1,\i}{2,\j}}
\end{psmatrix}
\end{document}


## Warning:

• mnode for \psframebox is not available out of the box. We can circumvent it by wrapping each item with \psframebox manually, but it will take more keystrokes!
• mnode=circle will use \pscirclebox to wrap the item. Unfortunately, \pscirclebox has no option to adjust its radius. It results in the size of each circle will vary depending on the size of the contained item. Only framesep is available to adjust the border. Sad!
-
@Karls students: looks very stylish too! Thanks for the pratical alternative! –  bobb_the_builder Mar 22 '13 at 23:15

Here's a very short solution using the tikz-cd package:

\documentclass{standalone}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[out=-90, in=90, column sep=small, row sep=15mm]
& & A & 1 \arrow{dll} & 2 \arrow{dl} & 3 \arrow{d} & 4 \arrow{dr} \\
B & \fbox{5} & 6 & \fbox{7} & 8 & \fbox{9} & 10 & \fbox{11} & 12
\end{tikzcd}
\end{document}


The result is this:

Note that the table entries created by this method will automatically be in math mode. Any entries for which this behavior is undesired should have their text enclosed in a \text{} command.

-
@ Charles Staats: very clear and simple approach - nice! –  bobb_the_builder Mar 23 '13 at 0:43