# How to put tikz overlay node on 4 corners of each tabular box?

Is it possible to put overlay tikz node on the crossing rules of a tabular. I tried, but the remember picture part doesn't work.

\documentclass[a4paper]{article}

\usepackage{array,tabularx,tikz,ragged2e,siunitx,xparse,hhline}
\usetikzlibrary{calc}

\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture,baseline=(#1)]\coordinate (#1) ;
}

\begin{document}

\begin{tabular}{cc}\hhline{\tikzmark{A}--}
A&B \\\hhline{-\tikzmark{B}-}
\end{tabular}

\begin{tikzpicture}[overlay,remember picture]
\fill (A) rectangle (B) ;

\end{tikzpicture}

\end{document}

• To reach the edge is easy, the problem in to reach the corner, that means to know height and depth of the tabular box. Even tex.stackexchange.com/questions/349045/… is depending of what is arround the box on the whole row. – Tarass Feb 13 '18 at 21:32
• You can get the y-coordinates (top and bottom) with \noalign{\pgfmark{top}}. The left and right is normally quite easy to get by putting a mark in a cell or before/after the tabular. Then you can calculate the coordinates with intersections. – Ulrike Fischer Feb 13 '18 at 21:36
• Possibly related: tex.stackexchange.com/questions/336782/… – user30471 Feb 13 '18 at 23:30
• Looking over the hhline documentation, it says nothing about inserting macros in with the keys =-~|:#tb*. There appears to be no equivalent to @{}. – John Kormylo Feb 14 '18 at 17:20

## 1 Answer

We know the minimum height and depth of one row, but that does not give us the height and depth of a particular row as it may contain large entries. If we create a row containing nothing but tikzmarks, then we can use a negative vskip to overlay it with the next row.

Note that the @{} generates multiple coordinates with same name. Only the last one counts.

A tikz matrix would have been easier.

\documentclass[a4paper]{article}

\usepackage{array,tabularx,tikz,ragged2e,siunitx,xparse,hhline}% only tikz is needed here
\usetikzlibrary{calc}

\newcommand{\tikzmark}[2][0pt]% #1 = y offset (optional), #2 = coordinate name
{\tikz[overlay,remember picture]\coordinate (#2) at (0pt,#1);}

\newcommand{\tikzrowmark}[2]% #1 = number of columns, #2 = coordinate name
{\multicolumn{#1}{c}{\tikzmark[\arraystretch\ht\strutbox]{#2}}%
\\[\dimexpr -\arraystretch\ht\strutbox-\arraystretch\dp\strutbox]}%

\begin{document}

\begin{tabular}{|@{\tikzmark{A west}\hspace{\tabcolsep}}c@{\hspace{\tabcolsep}\tikzmark{A east}}|c|}
\hline
\tikzrowmark{2}{A north}
A&B \\
\tikzrowmark{2}{A south}
\hline
\end{tabular}

\begin{tikzpicture}[overlay,remember picture]
\fill[yellow] (A west |- A north) rectangle (A east |- A south) ;

\end{tikzpicture}

\end{document}


• Thank you. But I need nodes for another purpose. The rectangle is only a mwe. – Tarass Feb 14 '18 at 13:14
• If you name the node (A), you have access to (A.south west) and (A.north east). If you want to put tikzmarks inside the tabular, you can use a savebox and [remember picture]. – John Kormylo Feb 14 '18 at 15:22
• I need a node between A and B, on the vertical line. – Tarass Feb 14 '18 at 16:13
• @johnkomylo The title of the question was wrong but my example shows what I want. Nodes on the corners of tabular boxes. – Tarass Feb 14 '18 at 16:16
• @johnkomylo Excellent !!! One can put tikz stuf in \noalign placed after the second \rowskip then use the @{} of the next line. Or naming the tikzmark using two counters and then have an unique xy reference to each one. – Tarass Feb 14 '18 at 19:33