# Drawing arrows as background under table text (tikz or other solution)

I want a background arrow in a column of text to show a propagating effect.

I tried using tikzmark and tikz, but the arrow overwrites the text, and tikz opacity doesn't play nice with regular text.

\documentclass[a6paper]{article}
\usepackage{array}
\usepackage{graphicx,colortbl,booktabs,environ,hhline}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\begin{document}
\pagestyle{empty}
\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture] \node (#1) {};}

\begin{table}
\centering
\resizebox{0.5\columnwidth}{!}{%
\newcommand{\bluecells}{\cellcolor{blue!08!white}\textcolor{black}}
\newcommand{\greencells}{\cellcolor{green!10!white}\textcolor{purple!3!black}}
\renewcommand{\arraystretch}{1.4}
\setlength{\extrarowheight}{1.2pt}
\begin{tabular}{m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}}
\hskip1ex & A & G\tikzmark{a} & X & G & R   \\\hhline{~-----}
%row 1
A & A &A &A &A &A   \\
%row 2
A &A &A &A &A   \\
%row 3
A &A &A &A &A   \\
%row 4
A &A & XX\tikzmark{b} & A & A & A   \\
%row 5
A & A & A & A & A   \\
\end{tabular}

\tikz[overlay,remember picture] \draw[-triangle 45,draw=green!20!white,line width=5pt,fill opacity=0.2] ($(a.south)+(-.2,-.3)$) -- ($(b.south)+(-.4,-.1)$);
}

\end{table}
\end{document}


I'd like to avoid redoing my tables in tikz just to get the arrow, because I have to convert them all. If I could somehow convince tikz to draw under the text, or even better to have the table redraw a second time over the whole thing, that would fix the problem.

Also, if anyone has a better suggestion than a background arrow to show propagating effects, I'd love to know. However, I have to do rows and colums, and make a sort of weave out of things, since sometimes the effects (arrows) cross over one another. Tikz will have no trouble doing that, if I can get it to play nice.

• I'd recomment to not use resizebox on a tabular environment as it weill lead to inconsistenz and sometimes extremely small font sizes. Instead, I'd change the column widths. – leandriis Oct 3 '19 at 16:03

What I can offer is a solution that draws the arrow in the background: eso-pic. (BTW, fill opacity is not the right key here.) However, your \resizebox screws things up, including the positioning mechanisms of TikZ. So I dropped it.

\documentclass[a6paper]{article}
\usepackage{array}
\usepackage{graphicx,colortbl,booktabs,environ,hhline}
\usepackage{tikz}
\usetikzlibrary{arrows,tikzmark}
\usepackage{eso-pic}
\begin{document}
\pagestyle{empty}

\begin{table}
\centering
%\resizebox{0.5\columnwidth}{!}{%
\newcommand{\bluecells}{\cellcolor{blue!08!white}\textcolor{black}}
\newcommand{\greencells}{\cellcolor{green!10!white}\textcolor{purple!3!black}}
\renewcommand{\arraystretch}{1.4}
\setlength{\extrarowheight}{1.2pt}
\begin{tabular}{m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}}
\hskip1ex & A & \tikzmarknode{a}{G} & X & G & R   \\\hhline{~-----}
%row 1
A & A &A &A &A &A   \\
%row 2
A &A &A &A &A   \\
%row 3
A &A &A &A &A   \\
%row 4
A &A & \tikzmarknode{b}{XX} & A & A & A   \\
%row 5
A & A & A & A & A   \\
\end{tabular}%}

\tikz[overlay,remember picture]
\draw[-triangle 45,draw=green!20!white,line width=5pt]
(a.south) -- ([yshift=-1em]b.south-|a);
}

\end{table}
\end{document}


• That looks like what I want, but I can't get it to build. It draws the table without the arrow and complains. Any problems with pdflatex? The specific error is: ! Undefined control sequence. l.18 \hskip1ex & A & \tikzmarknode {a}{G} & X & G & R \\\hhline{~-----} Any attempt to fix the code leads to everything becoming an undefined control sequence. There's no apparent reason for this complaint. – Guido Oct 3 '19 at 18:33
• @Guido Most likely you have an over-a-year-old TeX installation. \tikzmarknode was only added in 2018 to the tikzmark library. If you cannot update your TeX installation, you could use \tikznode from here instead of \tikzmarknode. – Schrödinger's cat Oct 3 '19 at 18:40
• I decided to overlay the regular non-tikz table on top of the tikz annotated table. That accomplishes background. I just use a \vbox{\hbox{}\vspace{}\hspace{}\hbox}} structure. It mostly works, but I'm noticing that tikz does something to the box size. It renders at a different x position, and spacing of things seems to be a little off. The overlay isn't perfect. Is this a known bug with Tikz? – Guido Oct 4 '19 at 3:22
• @Guido Well, without seeing an explicit example I am very hesitant to say there is a bug. That said, the above table is extremely easy to do with TikZ "only". – Schrödinger's cat Oct 4 '19 at 4:46
• I'm debating doing it. Thanks. – Guido Oct 4 '19 at 13:16

If you use the tikzmark tikz library then the coordinates defined by a tikzmark are available before they are defined in the document. The float and resizebox are a bit of a pain, but by putting the arrow command inside both but before the table then I get what I think you want.

\documentclass[a6paper]{article}
\usepackage{array}
\usepackage{graphicx,colortbl,booktabs,environ,hhline}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,tikzmark}
\begin{document}
\pagestyle{empty}

\begin{table}
\centering
\resizebox{0.5\columnwidth}{!}{%
\tikz[overlay,remember picture] \draw[-triangle 45,draw=green!20!white,line width=5pt,fill opacity=0.2] ($(pic cs:a)+(-.2,-.3)$) -- ($(pic cs:b)+(-.4,-.1)$);
\newcommand{\bluecells}{\cellcolor{blue!08!white}\textcolor{black}}
\newcommand{\greencells}{\cellcolor{green!10!white}\textcolor{purple!3!black}}
\renewcommand{\arraystretch}{1.4}
\setlength{\extrarowheight}{1.2pt}
\begin{tabular}{m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}m{1.5cm}}
\hskip1ex & A & G\tikzmark{a} & X & G & R   \\\hhline{~-----}
%row 1
A & A &A &A &A &A   \\
%row 2
A &A &A &A &A   \\
%row 3
A &A &A &A &A   \\
%row 4
A &A & XX\tikzmark{b} & A & A & A   \\
%row 5
A & A & A & A & A   \\
\end{tabular}

}

\end{table}
\end{document}