1

I tried to duplicate the result of the table in How to create a multirow red box for highlighting table results? using NiceTabular and tikz. The solution works well as long as cell-space-limits is small. When increasing it, the result becomes

enter image description here

As you see, the box is very close to the contents of the second row and exceeds the bottomrule. One workaround is to add \addlinespace, but this is suboptimal solution because sometimes we might clearly see how rows spacing differs. Is it possible to get a better one?

enter image description here

\documentclass{article}

\usepackage{booktabs}
\usepackage[x11names]{xcolor}

\usepackage{tikz}
\usetikzlibrary{fit}

\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-limits=1.1mm}

\begin{document}
    
\begin{table}[h]
    \caption{Box Test}
    \centering
    \begin{NiceTabular}{cccc}
          & A & B & C \\ \toprule
        I & 1 & 2 & 3 \\
        J & 4 & 5 & 6 \\
        K & 7 & 8 & 9 \\ \bottomrule
        \CodeAfter
        \tikz \node [draw=Coral3, fit = (3-1) (4-2)] { } ;
    \end{NiceTabular}
\end{table}

\begin{table}[h]
    \caption{Box Test}
    \centering
    \begin{NiceTabular}{cccc}
          & A & B & C \\ \toprule
        I & 1 & 2 & 3 \\ \addlinespace
        J & 4 & 5 & 6 \\
        K & 7 & 8 & 9 \\ \addlinespace \bottomrule
        \CodeAfter
        \tikz \node [draw=Coral3, fit = (3-1) (4-2)] { } ;
    \end{NiceTabular}
\end{table}
    
\end{document}

1 Answer 1

1

You could try to use the key inner ysep of Tikz in the node:

\documentclass{article}
\usepackage{booktabs}
\usepackage[x11names]{xcolor}

\usepackage{tikz}
\usetikzlibrary{fit}

\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-limits=1.1mm}

\begin{document}
    
\begin{table}[h]
    \caption{Box Test}
    \centering
    \begin{NiceTabular}{cccc}
          & A & B & C \\ \toprule
        I & 1 & 2 & 3 \\
        J & 4 & 5 & 6 \\
        K & 7 & 8 & 9 \\ \bottomrule
        \CodeAfter
        \tikz \node [inner ysep = -0.9mm, draw=Coral3, fit = (3-1) (4-2)] { } ;
    \end{NiceTabular}
\end{table}
\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .