![NiceTabular 内部的突出显示导致框超出规则](https://linux22.com/image/431646/NiceTabular%20%E5%86%85%E9%83%A8%E7%9A%84%E7%AA%81%E5%87%BA%E6%98%BE%E7%A4%BA%E5%AF%BC%E8%87%B4%E6%A1%86%E8%B6%85%E5%87%BA%E8%A7%84%E5%88%99.png)
我尝试复制表格中的结果如何创建多行红框来突出显示表格结果?使用NiceTabular
和tikz
。只要cell-space-limits
很小,解决方案就会很好。当增加它时,结果变成
如您所见,该框非常接近第二行的内容并超出了底部规则。一种解决方法是添加\addlinespace
,但这不是最佳解决方案,因为有时我们可能会清楚地看到行间距的不同。有可能得到更好的解决方案吗?
\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
inner ysep
您可以尝试在节点中使用 Tikz 的键:
\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}