Is it possible to highlight every cell with counters `iRow `and `jCol` in `NiceTabular`

highlightingnicematrixtikz-pgf

It is very common for me to need to place braces in matrix environment in a controlled fashion which I find NiceTabular environment suitable for such purpose.

One difficulty I encounter is that when tables are very large in size, it becomes harder to determine the position of each cell in the table. Is it possible to systematically highlight the cells numbers using the counters iRow and jCol as follows?

enter image description here

The following requirements are to be met

  1. The highlighting color and transparency should be controllable
  2. Highlighting should go exactly in the middle of each cell (even when \Block environment is used, cells of the \Block should still be highlighted)
  3. If possible, the highlighting should be done using a convenient key to be added in the options

My MWE

\documentclass[11pt, a4paper]{article}

\usepackage{nicematrix}

\usepackage{calc}
\newlength{\widthCell}
\newcommand{\phantombox}[2]{%
    \setlength{\widthCell}{\widthof{{Cell \arabic{iRow},\arabic{jCol}}}}%
    {#2}\llap{\parbox{\widthCell}{\centering\color{gray!25}#1}}%
    }

\begin{document}

\begin{NiceTabular}[hvlines,rules/color=[gray]{0.89},rules/width=0.2pt]{*{3}c}
    
    \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}}
    \\
    
    \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}}
    \\
    
    \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}} & \phantombox{\arabic{iRow},\arabic{jCol}}{Cell \arabic{iRow},\arabic{jCol}}
    \\
    
    \CodeAfter
    \SubMatrix{\{}{1-1}{3-1}{.}
    \SubMatrix{.}{1-2}{2-2}{\}}
    
    
\end{NiceTabular}

\end{document}

Best Answer

\documentclass{article}
\usepackage{nicematrix,tikz}

\ExplSyntaxOn
\NewDocumentCommand \HighLight { O { } }
  {
    \foreach \i in {1,...,\arabic{iRow}}
      \foreach \j in {1,...,\arabic{jCol}}
        { 
          \tikz [remember~picture, overlay] 
            \node [opacity=0.5] at (\i.5-|\j.5) { \Large \color{red} \i , \j } ;
        }
  }

\ExplSyntaxOff

\begin{document}

\begin{NiceTabular}{ccc}[hvlines,cell-space-limits=3pt]
\Block{2-2}{test} &           & test \\
                  &           & blabla \\
test              & some text & nothing 
\CodeAfter \HighLight
\end{NiceTabular}

\end{document}

As usual with nicematrix, you need several compilations.

Output of the above code

Related Question