[Tex/LaTex] Connect tables with arrows

arrowstablestikz-arrowstikz-pgf

I'm trying to do something similar to what is shown in the picture, but do not even know where to start.
I can get something similar with three tables and minipage environment. But I have no idea how to connect tables rows with arrows.
Maybe I should use tikz for that, but I can't found similar examples with tables.

\documentclass{beamer}

\usepackage{tabu}
\usepackage{color}
\usepackage{xcolor, colortbl}

\begin{document}
\begin{table}[!htb]
    Interleaving example \\
    \begin{minipage}{.3\linewidth}
      \centering
        \begin{tabu}{|c|c|}
          \hline
          \rowcolor{green!25} 1 & $Document_a$ \\
          \hline
          \rowcolor{green!25} 2 & $Document_b$ \\
          \hline
          \rowcolor{green!25} 3 & $Document_c$ \\
          \hline
        \end{tabu}
        Ranking A
    \end{minipage}
    \begin{minipage}{.3\linewidth}
      \centering
        \begin{tabu}{|c|c|}
          \hline
            \rowcolor{green!25} 1 & $Document_a$ \\
          \hline
            \rowcolor{red!25} 2 & $Document_e$ \\
          \hline
           \rowcolor{green!25} 3 & $Document_b$ \\
          \hline
        \end{tabu}
        Shown to user
    \end{minipage}
    \begin{minipage}{.3\linewidth}
      \centering
        \begin{tabu}{|c|c|}
          \hline
          \rowcolor{red!25} 1 & $Document_e$ \\
          \hline
          \rowcolor{red!25} 2 & $Document_d$ \\
          \hline
          \rowcolor{red!25} 3 & $Document_f$ \\
          \hline
        \end{tabu}
        Ranking B
    \end{minipage} 
\end{table}

\end{document}

Desired results

Best Answer

I would use a tikz matrix of (math) nodes, together with some fancy arrows from the shapes.arrows library of tikz:

enter image description here

Here is the code:

\documentclass[border=5mm,tikz]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes.arrows}

\begin{document}
    \begin{tikzpicture}[>=stealth,->,shorten >=2pt,looseness=.5,auto,
        Red/.style={fill=red,text=white},
        fat arrow/.style={single arrow,shape border rotate=90,
                          thick,draw=blue!70,fill=blue!30,
                          minimum height=10mm},
        empty node/.style={minimum height=10mm,fill=none},
      ]
      \matrix (M)[matrix of math nodes,row sep=2mm,column sep=10mm,
                        nodes={text width=20mm,rectangle,fill=green!20}
      ]{
          \text{Document}_A & \text{Document}_a & \text{Document}_e\\
          |[Red]|\text{Document}_B & \text{Document}_b & |[Red]|\text{Document}_f\\
          \text{Document}_C & \text{Document}_c & |[Red]|\text{Document}_g\\
          |[empty node]|& |[empty node]|& |[empty node]|\\
          \text{Ranking A}& \text{Ranking A}& \text{Ranking A}\\
       };
       \draw[red,->](M-2-1.east)--(M-2-2.west);
       \draw[red,->](M-2-3.west)--(M-2-2.east|-M-2-3.west);
       \draw[red,->](M-3-3.west)--(M-2-2.south east);
       \node at (M-4-1) [fat arrow]{};
       \node at (M-4-2) [fat arrow]{};
       \node at (M-4-3) [fat arrow]{};
    \end{tikzpicture}
\end{document}

A few words of explanation:

  • The (M) in \matrix (M) means that the nodes in the matrix can be referred to as M-<row>-<col>
  • If you use matrix of math nodes then it is better to write \text{Document}_A etc, (the \text command is from the amsmath package), because otherwise it looks like D*o*c*u*m*e*n*t (the OP's MWE has this problem). If there is more text than mathematics in the nodes then use matrix of nodes instead of matrix of math nodes
  • I have set the default fill colour of the cells to green!20, assuming that this is the most common background
  • For the red cells I have overridden the default background with |[Red]| using the Red style
  • The empty node is used to control the (minimum) height of each of these nodes and to allow us to put a fat arrow there later
  • You can use east, west, south east, ... modifiers to control where the arrows leave and enter the nodes
  • The cells are of slightly different heights because of the different sizes of the subscripts. This is the reason for the specification of (M-2-2.east|-M-2-3.west) for the arrow from Document_f to Document_b. All this does is make the arrow perpendicular to the sides of the rectangle.
  • the Red, empty node and fat arrow styles make the code easier to read and easier to modify.