TransWikia.com

Highlighting inside NiceTabular causes boxes to go outside rules

TeX - LaTeX Asked on June 16, 2021

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}

One Answer

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

Answered by F. Pantigny on June 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP