NiceTabular 中 arraystretch 的奇怪行间距

NiceTabular 中 arraystretch 的奇怪行间距

大家晚上好,祝大家新年快乐。

我正在尝试获取一个 NiceTabular(NiceMatrix 包中的),其中包含一些文本,因为我希望它比正常情况更通透,所以我使用了\def\arraystretch{2}。但是,我的表格中的结果非常奇怪,行间不均匀,实际上取决于行:第一行和第二行之间的行间很大,然后是正常行间,然后倒数第二行和最后一行之间的行间更大。

在此处输入图片描述

您能否帮助我了解那里发生了什么,以及如何确保一个单元格中的线条彼此之间间距相等?您会使用其他任何方法来制作“通风”桌子吗?

我还试图摆脱表格中每行左侧和右侧的任何水平空间,以便边框与左侧的文本和右侧的数字对齐 - 如果您对如何做有任何想法,我将不胜感激。

非常感谢大家!

这是我的代码:

\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{nicematrix}

\begin{document}

\def\arraystretch{2}

\noindent\begin{NiceTabular}{b{5.5cm}b{1.5cm}}[code-before =
{\tikz \draw [black] (row-3-|col-1) -- (row-3-|col-3) ;
\tikz \draw [black] (row-4-|col-1) -- (row-4-|col-3) ;
\tikz \draw [black] (row-5-|col-1) -- (row-5-|col-3) ;
\tikz \draw [black] (row-6-|col-1) -- (row-6-|col-3) ;
\tikz \draw [black] (row-7-|col-1) -- (row-7-|col-3) ;
\tikz \draw [black] (row-8-|col-1) -- (row-8-|col-3) ;
}]
Only one row looks fine & \Block[r]{1-1}{1} \\
Two rows have a very big space between them & \Block[r]{1-1}{2} \\
Three rows show one small space first, and then a bigger one, but not too bad & \Block[r]{1-1}{3} \\
Four rows look much weirder, with big space between the first two rows, small space then, and big space again& \Block[r]{1-1}{4} \\
Five rows has only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. & \Block[r]{1-1}{5} \\
Six rows is even weirder with only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. & \Block[r]{1-1}{5} \\
\end{NiceTabular}


\end{document}

答案1

正如我看到/理解您的问题一样,使用该NiceTabular软件包并不是实现预期目标的最佳工具。例如,tabularray您可以更轻松、更简单地使用它:

\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{tabularray}

\begin{document}

    \begin{tblr}{hline{2-Z},
                 colspec = {Q[j,b, wd=5.5cm] Q[r,b, wd=1.5cm]},
                 rowsep  = 2ex,
                 }
Only one row looks fine &   1   \\
Two rows have a very big space between them 
                        &   2   \\
Three rows show one small space first, and then a bigger one, but not too bad 
                        &   3   \\
Four rows look much weirder, with big space between the first two rows, small space then, and big space again
                        &   4   \\
Five rows has only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. 
                        &   5   \\
Six rows is even weirder with only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. 
                        &   6   \\
    \end{tblr}
\end{document}

在此处输入图片描述

答案2

将此代码用于code-before\CodeAfter

C

(没有第 8 行)

\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{nicematrix}

\begin{document}
    
    \renewcommand{\arraystretch}{2} % expand the cells
    
    \noindent\begin{NiceTabular}{b{5.5cm}b{1.5cm}}[
        code-before =
        \tikz \draw  (2-|1) -- (2-|3); 
        \tikz \draw  (3-|1) -- (3-|3);
        \tikz \draw  (4-|1) -- (4-|3); 
        \tikz \draw  (5-|1) -- (5-|3);
        \tikz \draw  (6-|1) -- (6-|3);  
        \tikz \draw  (7-|1) -- (7-|3);  
        ]
        Only one row looks fine & \Block[r]{1-1}{1} \\
        Two rows have a very big space between them & \Block[r]{1-1}{2} \\
        Three rows show one small space first, and then a bigger one, but not too bad & \Block[r]{1-1}{3} \\
        Four rows look much weirder, with big space between the first two rows, small space then, and big space again& \Block[r]{1-1}{4} \\
        Five rows has only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. & \Block[r]{1-1}{5} \\
        Six rows is even weirder with only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. & \Block[r]{1-1}{6} \\
    \end{NiceTabular}
    
    \newpage
    
    \noindent\begin{NiceTabular}{b{5.5cm}b{1.5cm}}
        Only one row looks fine & \Block[r]{1-1}{1} \\
        Two rows have a very big space between them & \Block[r]{1-1}{2} \\
        Three rows show one small space first, and then a bigger one, but not too bad & \Block[r]{1-1}{3} \\
        Four rows look much weirder, with big space between the first two rows, small space then, and big space again& \Block[r]{1-1}{4} \\
        Five rows has only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. & \Block[r]{1-1}{5} \\
        Six rows is even weirder with only one big space between first and second row, then ok, then an even bigger one between the penultimate and the ultimate. & \Block[r]{1-1}{6} \\
        \CodeAfter      
        \tikz \draw  (2-|1) -- (2-|3); 
        \tikz \draw  (3-|1) -- (3-|3); 
        \tikz \draw  (4-|1) -- (4-|3); 
        \tikz \draw  (5-|1) -- (5-|3);
        \tikz \draw  (6-|1) -- (6-|3);  
        \tikz \draw  (7-|1) -- (7-|3);      
    \end{NiceTabular}   
    
\end{document}

相关内容