5

I have noticed a strange behaviour of values of arraystretch between 0 and 1, on specific rows in a NiceTabular environment, as soon as such row has a \Block{k-n} when k takes any value, but n is strictly greater than one.

Indeed, I have a table, built with nicematrix (I have to use this very environment for other reasons) where I would like to reduce the space between rows. I noticed that on rows where I have blocks made with strictly more than one column, arraystretch works very well for values greater than one, but for values lower than one all the rows where there is a \Block with strictly more than one column, the height of the row is not reduced.

Am I missing something? Is there any way to overcome this, and reduce the size of all the rows of my code (I tried with a negative value in cell-space-limits, but it does not help much, unfortunately.

Here is a reduced LaTeX code that summarizes it (the problem is the row in yellow).

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

\begin{document}

\begin{verbatim}
With \def\arraystretch{1}:
\end{verbatim}

\def\arraystretch{1}

\begin{NiceTabularX}{9cm}{XXXX}[hvlines]
    \Block{2-1}{A\\E} & B & C & D \\
     & F & G & H \\
    I & J & \Block{1-2}{KL} & \\
    M & N & O & P\\
\end{NiceTabularX}

\vspace{5mm}

\begin{verbatim}
With \def\arraystretch{2}:
\end{verbatim}

\def\arraystretch{2}

\begin{NiceTabularX}{9cm}{XXXX}[hvlines]
    \Block{2-1}{A\\E} & B & C & D \\
     & F & G & H \\
    I & J & \Block{1-2}{KL} & \\
    M & N & O & P\\
\end{NiceTabularX}

\vspace{5mm}

\begin{verbatim}
With \def\arraystretch{0.5}:
\end{verbatim}

\def\arraystretch{0.5}

\begin{NiceTabularX}{9cm}{XXXX}[hvlines]
    \Block{2-1}{A\\E} & B & C & D \\
     & F & G & H \\
    \RowStyle[rowcolor=yellow!50]{}
    I & J & \Block{1-2}{KL} & \\
    M & N & O & P\\
\end{NiceTabularX}
    
\end{document}

enter image description here

Thank you so much to all, have an excellent evening!

Simon

4
  • By design, the value of \arraystretch is set back to 1 in the small arrays constructed by \Block. Moreover, a monocolumn \Block has a width which is taken into account for the construction of the array but its height and depth are not taken into account: you have create the space by yourself. So, your ouput is the expected one. Commented Jan 23, 2022 at 9:07
  • Alright, thank you very much! Is there any way to overcome this rule that \arraystretch is set back to 1, and thus to have smaller (in height) rows?
    – Simon
    Commented Jan 23, 2022 at 9:12
  • I will add a feature in nicematrix (I'm the author of nicematrix) to have the behaviour you describe. Commented Jan 23, 2022 at 9:27
  • Wow. Then I can congratulate and thank you a million for this package, it's so efficient and easy to use to make beautiful tables! And add one thank in advance for this new feature.
    – Simon
    Commented Jan 23, 2022 at 9:53

1 Answer 1

3

By design, a command \Block of nicematrix sets \arraystretch to 1 before the composition of the content of a block.

However, since version 6.5 (2022-01-23), there is key respect-arraystretch which prevents that behaviour. That key can be used for an individual \Block, for an environment of nicematrix (such as {NiceTabular}) or with \NiceMatrixOptions.

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

\begin{document}

\def\arraystretch{0.5}

\begin{NiceTabularX}{9cm}{XXXX}[hvlines,respect-arraystretch]
    \Block{2-1}{A\\E} & B & C & D \\
     & F & G & H \\
    \RowStyle[rowcolor=yellow!50]{}
    I & J & \Block{1-2}{KL} & \\
    M & N & O & P\\
\end{NiceTabularX}
    
\end{document}

As usual with nicematrix, you need several compilations.

Output of the above code

You must log in to answer this question.

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