[Tex/LaTex] Big arrow across the table (overlay)

arrows

As shown in picture, is there a way to achieve this?

enter image description here

\documentclass[12pt,a4paper]{article}

\usepackage{rotating} % sidewaytables


\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}



\begin{sidewaystable}

\begin{tikzpicture}
\matrix (m) [matrix of math nodes,left delimiter=|, right delimiter=|] {
    & K=3 & K=4 & K=5 & K=6 & K=7 & K=8 & K=9 & K=10 & K=11 & K=12\\
    \hline
    C=2 &4&7&10&12&14&16&18&20&&\\ \hline
    C=3 &4&7&11&16&21&24&27&30&&\\ \hline
    C=4 &4&7&11&16&22&29&36&40&&\\ \hline
    C=5 &4&7&11&16&22&29&37&46&&\\ \hline
    C=6 &4&7&11&16&22&29&37&46&&\\ \hline
    C=7 &4&7&11&16&22&29&37&46&&\\ \hline
    C=8 &4&7&11&16&22&29&37&46&&\\ \hline
    C=9 &4&7&11&16&22&29&37&46&&\\ \hline
    C=10&4&7&11&16&22&29&37&46&&\\
};
\draw[->,red,thick] (m-2-2.west) -- (m-2-3.east);
\draw[->,red,thick] (m-4-4.west) -- (m-4-7.east);
\draw[->,red,thick] (m-6-7.west) -- (m-6-8.east);
\draw[->,red,thick] (m-9-3.west) -- (m-9-6.east);
\end{tikzpicture}

\end{sidewaystable}


\end{document}

This works OK. But how do I make it into "tabular" look, ie the vertical lines that separates the columns.

Best Answer

This approach uses stackengine package's \topinset macro to overlay the table with the arrows. Perhaps a better arrow could be constructed... I just added a \rightarrow to the end of a long \rule.

The key to making the construction easy was reckoning the four lengths, \cellv, \cellh, \vertoffset, and \horzoffset. Once that is done, the horizontal and vertical shifts for each arrow are integer multiples of \cellh and \cellv.

\documentclass[12pt,a4paper]{article}

\usepackage{amsmath,enumerate}
\usepackage{rotating} % sidewaytables
\usepackage{xcolor}
\usepackage{stackengine}
\newlength\cellv
\newlength\cellh
\newlength\vertoffset
\newlength\horzoffset
\setlength{\cellv}{\baselineskip}
\setlength{\cellh}{3.6em}
\setlength\vertoffset{.4\baselineskip}
\setlength\horzoffset{1.5em}
\def\stackalignment{l}
\newcommand\myarrow[1]{$\color{red}\rule[.47ex]{#1}{.6pt}\!\!\!\rightarrow$}

\begin{document}

\begin{sidewaystable}

\[
\topinset{\myarrow{1.5\cellh}}{%
\topinset{\myarrow{3.5\cellh}}{%
\topinset{\myarrow{5.5\cellh}}{%
\(
    \begin{array}{c|c|c|c|c|c|c|c|c|c|c}
    & K=3 & K=4 & K=5 & K=6 & K=7 & K=8 & K=9 & K=10 & K=11 & K=12\\
    \hline
    C=2 &4&7&10&12&14&16&18&20&&\\ \hline
    C=3 &4&7&11&16&21&24&27&30&&\\ \hline
    C=4 &4&7&11&16&22&29&36&40&&\\ \hline
    C=5 &4&7&11&16&22&29&37&46&&\\ \hline
    C=6 &4&7&11&16&22&29&37&46&&\\ \hline
    C=7 &4&7&11&16&22&29&37&46&&\\ \hline
    C=8 &4&7&11&16&22&29&37&46&&\\ \hline
    C=9 &4&7&11&16&22&29&37&46&&\\ \hline
    C=10&4&7&11&16&22&29&37&46&&
    \end{array}
\)
}{1\cellv+\vertoffset}{3\cellh+\horzoffset}
}{2\cellv+\vertoffset}{5\cellh+\horzoffset}
}{3\cellv+\vertoffset}{7\cellh+\horzoffset}
\]
\end{sidewaystable}

\end{document}

enter image description here