# Connect three floating tables with arrows

In a word document I have three tables connected by arrows, as in the figure below, that I would like to reproduce with Latex. My question is 1) how to create these three tables so I can position them more or less as in the figure and 2) how to draw arrows connecting cells of different tables.

-
Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. You can also insert your image directly in here instead of a link –  Christian Hupfer Jul 9 '14 at 20:39
A job for tikzmark if I've ever seen one! :-) –  Paul Gessler Jul 9 '14 at 20:55
Annotating Tables With Tikz; Adding Arrows might be helpful for you or someone else tackling this –  cmhughes Jul 9 '14 at 20:56
pst-node could also be helpful here. –  Bernard Jul 9 '14 at 21:12

This answer uses tikzmark as mentioned in the comments on your question. Basically, the idea is to typeset the tables as normal and then overlay them with a tikzpicture which draws the connecting arrows.

I've created one tabular for the top two tables and another for the third. The only use of tikz here is to create the arrows in the second column.

\newcommand*{\myarrow}[1][50]{\tikz{\draw [black!#1, {Stealth[length=7.5pt]}-, thick] (0,0) -- (.35,0);}}


defines a macro, \myarrow[], which takes a single optional argument which determines how dark or heavy the arrow will be as a percentage. The default is 50 and I've also used 85 in the example.

The tabular environments use the packages array and dcolumn and two customised columns:

\newcolumntype{d}{D{.}{.}{2}}
\newcolumntype{o}{>{$}c<{$}}


The first centres the column on the decimal point for numbers with at most 2 decimal places. This also uses maths mode. The second just creates a centred maths mode.

\tikzmark{} is used in the tabular environments to mark coordinates for use when drawing the arrows later. This code does not affect the typesetting of the tables themselves, however.

The marks are then used in a tikzpicture which overlays the tables. This picture includes the commands to draw the arrows connecting the tables.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark, arrows.meta, calc, bending}
\usepackage{array, dcolumn}
\newcolumntype{d}{D{.}{.}{2}}
\newcolumntype{o}{>{$}c<{$}}
\newcommand*{\myarrow}[1][50]{\tikz{\draw [black!#1, {Stealth[length=7.5pt]}-, thick] (0,0) -- (.35,0);}}
\begin{document}
\begin{table}
\begin{tabular}{oco|d!{$\dots$}d}
\textbf{l}    &   &   t   &   \multicolumn{1}{o!{$\dots$}}{P_{L1}}    &   \multicolumn{1}{o}{P_{Ln}}\\\cline{1-1}\cline{3-5}
\tikzmark{p1}1    &   \myarrow    &   1   &   0.40    &   0.58\\
\tikzmark{p2}1    &   \myarrow    &   2   &   0.41    &   0.60\\
\tikzmark{p3}2    &   \myarrow[85]    &   3   &   0.20    &   0.41\\
\tikzmark{p4}1    &   \myarrow    &   4   &   0.39    &   0.60\\
\vdots  &   &   \vdots  &   \multicolumn{1}{o}{\vdots}  &   \vdots\\
\tikzmark{p5}2    &   \myarrow[85]    &   M   &   0.21    &   0.43\\
\end{tabular}\\[\bigskipamount]
\begin{tabular}{o|d!{$\dots$}dd}
c_i   &   \multicolumn{1}{o!{$\dots$}}{P_{L1}}    &   \multicolumn{1}{o}{P_{Ln}}  &   \multicolumn{1}{o}{Q_{L1}}\\\hline
\tikzmark{c1}c_1  &   0.40    &   0.59    &   0.10\\
\tikzmark{c2}c_2  &   0.21    &   0.42    &   0.05\\
\vdots    &   \multicolumn{1}{o}{\vdots}  &   \vdots  &   \vdots\\
c_k   &   0.32    &   0.33    &   0.02\\
\end{tabular}
\end{table}
\begin{tikzpicture}[remember picture, overlay, -{Stealth[length=7.5pt]}, draw]
\coordinate (c1coord) at ($({pic cs:c1}) + (-.25em,.25em)$);
\coordinate (c2coord) at ($({pic cs:c2}) + (-.25em,.25em)$);
\foreach \i in {1,...,5}
\coordinate (p\i1) at ($({pic cs:p\i}) + (-.25em,.25em)$);
\coordinate (p12) at ($(p11) + (-1em,-1em)$);
\coordinate (p13) at ($(c1coord) + (-1em,1em)$ -| p12);
\coordinate (p22) at ($(p21) + (-1.5em,-1em)$);
\coordinate (p23) at ($(c1coord) + (-1.5em,1em)$ -| p22);
\coordinate (p32) at ($(p31) + (-2.5em,-1em)$);
\coordinate (p33) at ($(c2coord) + (-2.5em,1em)$ -| p32);
\coordinate (p42) at ($(p41) + (-2em,-1em)$);
\coordinate (p43) at ($(c1coord) + (-2em,1em)$ -| p42);
\coordinate (p52) at ($(p51) + (-3em,-1em)$);
\coordinate (p53) at ($(c2coord) + (-3em,1em)$ -| p52);
\foreach \i in {1,2,4}
\draw [black!50] (p\i1) to[out=-180, in=90] (p\i2) -- (p\i3) to[out=-90, in=180] (c1coord);
\foreach \i in {3,5}
\draw [black!85, dashed] (p\i1) to[out=-180, in=90] (p\i2) -- (p\i3) to[out=-90, in=180] (c2coord);
\end{tikzpicture}
\end{document}


-

How about TikZ and a matrix of math nodes?

The code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}
% The matrix entries
\matrix[
matrix of math nodes,
nodes in empty cells,
text depth=0.5ex,
text height=2ex,
] (mat)
{
l &  & t & P_{L_{1}} & \cdots & P_{L_{n}} \\
1 & & 1 & 0.40 & \cdots & 0.58 \\
1 & & 2 & 0.40 & \cdots & 0.58 \\
2 & & 3 & 0.40 & \cdots & 0.58 \\
1 & & 2 & 0.40 & \cdots & 0.58 \\
\vdots & &  \vdots & \vdots & & \vdots \\
2 & & 5 & 0.40 & \cdots & 0.58 \\
\\[10pt]
\mathbf{c}_{j} & P_{L_{1}} & \cdots & P_{L_{n}} & Q_{L_{1}} \\
\mathbf{c}_{1} & 0.32 & \cdots & 0.34 & 0.10 \\
\mathbf{c}_{2} & 0.32 & \cdots & 0.34 & 0.10 \\
\vdots &  \vdots & & \vdots & \vdots \\
\mathbf{c}_{k} & 0.32 & \cdots & 0.34 & 0.10 \\
};

% The arrows in the second column
\begin{scope}[line width=1.5pt,<-,shorten >= -2pt,shorten <= -2pt]
\foreach \Fila in {2,3,5}
\draw[gray]
(mat-\Fila-2.west) -- (mat-\Fila-2.east);
\foreach \Fila in {4,7}
\draw
(mat-\Fila-2.west) -- (mat-\Fila-2.east);
\end{scope}

% The rules for the matrices
\draw (mat-1-1.south west) -- (mat-1-1.south east);
\draw (mat-1-3.south west) -- (mat-1-6.south east);
\draw (mat-1-4.north west) -- (mat-1-4.north west|-mat-7-4.south west);
\draw (mat-9-2.north west) -- (mat-9-2.north west|-mat-13-2.south west);
\draw (mat-9-1.south west) -- (mat-9-5.south east);

% The curved arrows connecting entries
\begin{scope}[
>=latex,
rounded corners
]
\foreach \Fila/\Corr in {2/8pt,3/15pt,5/22pt}
\draw[->,gray]
(mat-\Fila-1.west) -- ++(-\Corr,0) |- (mat-9-1.west);
\foreach \Fila/\Corr in {4/30pt,7/37pt}
\draw[->,dashed]
(mat-\Fila-1.west) -- ++(-\Corr,0) |- (mat-11-1.west);
\end{scope}
\end{tikzpicture}

\end{document}

-