![NiceTabular 中 arraystretch 的奇怪行间距](https://linux22.com/image/444597/NiceTabular%20%E4%B8%AD%20arraystretch%20%E7%9A%84%E5%A5%87%E6%80%AA%E8%A1%8C%E9%97%B4%E8%B7%9D.png)
大家晚上好,祝大家新年快乐。
我正在尝试获取一个 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
。
(没有第 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}