# Positioning tikz arrows to coordinates inside tabulars

I need to create a slide with multiple tabulars and use arrow to point to elements inside those tabulars.

However, I'm having trouble to specify where tabulars, texts and arrows should appear. How can I do this?

My minimal non-working example follows:

\documentclass{beamer}              % only frames
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning,matrix}
\newcommand{\tikzmark}[1]{\tikz[remember picture] \node[coordinate] (#1) {#1};}

\begin{document}
\begin{frame}\frametitle{Example}
\begin{tabular}{ccccc}
\tikzmark{col1}
\begin{tabular}{|c|}\hline
\tikzmark{elem1}2\\\hline
3\\\hline
7\\\hline
6\\\hline
1\\\hline
5\\\hline
4\\\hline
\end{tabular}&
\tikzmark{col2}
\begin{tabular}{|c|}\hline
\tikzmark{elem2}4\\\hline
2\\\hline
1\\\hline
3\\\hline
6\\\hline
7\\\hline
5\\\hline
\end{tabular}&
\tikzmark{mat}
\begin{tabular}{|c|c|c|c|}\hline
1&0&1&0\\\hline
1&0&0&1\\\hline
0&1&0&1\\\hline
0&1&0&1\\\hline
0&1&0&1\\\hline
1&0&1&0\\\hline
1&0&1&0\\\hline
\end{tabular}&
\tikzmark{sigMat}
\begin{tabular}{|c|c|c|c|}\hline
\tikzmark{elem3}2&1&2&1\\\hline
2&1&4&1\\\hline
1&2&1&2\\\hline
\end{tabular}
\end{tabular}
\begin{tikzpicture}[remember picture]
\node [above=.01cm of col2] {\tiny Text Above columns};
\node[above=.01cm of mat] {\tiny Above 1st matrix};
\node[above=.1cm of sigMat]{\tiny Above 2nd matrix};

\node[above=2cm of mat,text width=6cm] (txt1) {Arrows go from here to...};

\path[draw,->] (txt1.south west) -- node {goes to 1st elem} (elem1);
\path[draw,->] (txt1.south) -- node {goes to 2nd elem} (elem2);
\path[draw,->] (txt1.south east) -- node {goes to 3rd elem} (elem3);
\end{tikzpicture}
\end{frame}

\end{document}


This results in the following slide:

• There is a specific library for that, tikzmark. And you place the marks at weird places, and the output is a result of this. Why did you put \tikzmark{mat} where you put it? – Schrödinger's cat Aug 22 '19 at 20:48
• I put \tikzmark{mat} there to be a point referring to the 7x4 matrix. – Marc Kees Aug 22 '19 at 21:03
• The main issue is that you forgot overlay in the tikzpicture. It needs to become \begin{tikzpicture}[remember picture,overlay]. – Schrödinger's cat Aug 22 '19 at 21:12

The main issue is that you forgot overlay in your tikzpicture. However, this is also to inform you that there is the tikzmark library, with which you can make the tables nodes, and elements subnodes.

\documentclass{beamer}              % only frames
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning,matrix,fit,tikzmark}

\begin{document}
\begin{frame}
\frametitle{Example}
\begin{tabular}{ccccc}
\tikzmarknode{col1}{\begin{tabular}{|c|}\hline
\subnode{elem1}{2}\\\hline
3\\\hline
7\\\hline
6\\\hline
1\\\hline
5\\\hline
4\\\hline
\end{tabular}}&
\tikzmarknode{col2}{\begin{tabular}{|c|}\hline
\subnode{elem2}{4}\\\hline
2\\\hline
1\\\hline
3\\\hline
6\\\hline
7\\\hline
5\\\hline
\end{tabular}}&
\tikzmarknode{col3}{\begin{tabular}{|c|c|c|c|}\hline
1&0&1&0\\\hline
1&0&0&1\\\hline
0&1&0&1\\\hline
0&1&0&1\\\hline
0&1&0&1\\\hline
1&0&1&0\\\hline
1&0&1&0\\\hline
\end{tabular}}&
\tikzmarknode{sigMat}{\begin{tabular}{|c|c|c|c|}\hline
\subnode{elem3}{2}&1&2&1\\\hline
2&1&4&1\\\hline
1&2&1&2\\\hline
\end{tabular}}
\end{tabular}
\begin{tikzpicture}[remember picture,overlay]
\node[fit=(col1)(col2)(col3)](cols){};
\node[above=.01cm of cols,font=\tiny] {Text Above columns};
\node[above=.01cm of col1,font=\tiny] {Above 1st matrix};
\node[above=.1cm of sigMat,font=\tiny]{Above 2nd matrix};
%
\node[above=1cm of cols.north east] (txt1) {Arrows go from here to\dots};
%
\path[draw,->] (txt1.south west) -- node[sloped,font=\tiny,above] {goes to 1st elem} (elem1);
\path[draw,->] (txt1.south) -- node[sloped,font=\tiny,above] {goes to 2nd elem} (elem2);
\path[draw,->] (txt1.south east) -- node[sloped,font=\tiny,above] {goes to 3rd elem} (elem3);
\end{tikzpicture}
\end{frame}
\end{document}


• I tried to build your code with xelatex and it puts arrows in slightly different places, outside columns and matrix. However, using lualatex it works well. – Marc Kees Aug 23 '19 at 18:20
• @MarcKees This is strange, but probably worth a separate question, which may be answered by some xelatex expert, which I am not. – Schrödinger's cat Aug 23 '19 at 18:31
• I created a new question as you suggested: tex.stackexchange.com/questions/505465/… – Marc Kees Aug 23 '19 at 18:47
• @MarcKees I already upvoted it. – Schrödinger's cat Aug 23 '19 at 18:47