5

I'm trying to write a relatively wide matrix with the package nicematrix, using the environment pNiceMatrix. I can fix the global width using the option [columns-width=xx], and if I fix it to 0mm, it will try to compact the matrix columns to the maximum. But even then, the spacing around the horizontal dots (\cdots), could be reduced. I am not able to use the options using {Wc{2mm}} - nicematrix reads the option as a string.

Here is an example that compiles:

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\[
\begin{pNiceMatrix}[columns-width=0mm]
  %nicematrix
  \xi^{(\gamma,1)}_{1,1} & \cdots & \xi^{(\gamma,1)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,1)}_{n_{Y},1} & \cdots & \xi^{(\gamma,1)}_{n_{Y},M_{n_{Y}}} \\
  \Vdots                 &        &                             &         &                            &        & \vdots \\
  \xi^{(\gamma,N)}_{1,1} & \cdots & \xi^{(\gamma,N)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,N)}_{n_{Y},1} & \cdots & \xi^{(\gamma,N)}_{n_{Y},M_{n_{Y}}} 
\end{pNiceMatrix}
\]
\end{document}

And produces this output:

enter image description here

I have tried this, based on the first example in section 8 "The width of the columns" of the documentation :

\[
\begin{pNiceMatrix}{cWc{2mm}cWc{2mm}cWc{2mm}c}
  %nicematrix
  \xi^{(\gamma,1)}_{1,1} & \cdots & \xi^{(\gamma,1)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,1)}_{n_{Y},1} & \cdots & \xi^{(\gamma,1)}_{n_{Y},M_{n_{Y}}} \\
  \Vdots                 &        &                             &         &                            &        & \vdots \\
  \xi^{(\gamma,N)}_{1,1} & \cdots & \xi^{(\gamma,N)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,N)}_{n_{Y},1} & \cdots & \xi^{(\gamma,N)}_{n_{Y},M_{n_{Y}}} 
\end{pNiceMatrix}
\]

But only to get :

enter image description here

How can I reduce the width of the columns 2,4,6 ?

I followed the quick install tutorial for texlive so I should have the latest version of nicematrix (5.19).

4
  • If you look at the examples in section 8 none have NiceMatrix supporting the c{2mm}
    – daleif
    Aug 3, 2021 at 11:42
  • Welcome to TeX.SE. The pNiceMatrix environment is like the pmatrix environment provided by amsmath, which means it doesn't accept column specifications. The [columns-width=0mm] tells latex that each column should have minimum width of 0mm. Try something like [columns-width=1cm] and see if that helps your solution.
    – rbrignall
    Aug 3, 2021 at 11:44
  • Alright, I remove the edit then and create a new answer! And yes, there was no hint that it would work, but also no example how showing how to reduce the size of the matrix on the environment pNiceMatrix
    – Kramer84
    Aug 3, 2021 at 11:44
  • @rbrignall Thank you, I have tried different values of for [columns-width=xx], and somehow, once the indicated width is smaller than the minimal possible width considering the size of the different elements, the width does not change anymore. In the actual implementation of the pMatrixEnvironment, setting columns-width to 0 ensures that it will always have the minimal size possible. But it may not be the cleanest way, and did not solve my issue.
    – Kramer84
    Aug 3, 2021 at 12:05

2 Answers 2

6

Since {pNiceMatrix} is similar to {pmatrix} of amsmath, it does not take in argument for the format of the array.

However, nicematrix provides {pNiceArray} with a mandatory argument which is the format. The environment {pNiceArray} is merely an environment {NiceArray} (similar to array) with @{} at both sides of the format and surrounded by parenthesis (with \left( and \right)).

Nevertheless, for what you want to acheive, the best solution is probably changing the value of \arraycolsep (as said in another answer).

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\[
\begin{pNiceMatrix}
  \xi^{(\gamma,1)}_{1,1} & \cdots & \xi^{(\gamma,1)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,1)}_{n_{Y},1} & \cdots & \xi^{(\gamma,1)}_{n_{Y},M_{n_{Y}}} \\
  \Vdots                 &        &                             &         &                            &        & \vdots \\
  \xi^{(\gamma,N)}_{1,1} & \cdots & \xi^{(\gamma,N)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,N)}_{n_{Y},1} & \cdots & \xi^{(\gamma,N)}_{n_{Y},M_{n_{Y}}} 
\end{pNiceMatrix}
\]


\[
\begin{pNiceArray}{cWc{2mm}cWc{2mm}cWc{2mm}c}
  \xi^{(\gamma,1)}_{1,1} & \cdots & \xi^{(\gamma,1)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,1)}_{n_{Y},1} & \cdots & \xi^{(\gamma,1)}_{n_{Y},M_{n_{Y}}} \\
  \Vdots                 &        &                             &         &                            &        & \vdots \\
  \xi^{(\gamma,N)}_{1,1} & \cdots & \xi^{(\gamma,N)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,N)}_{n_{Y},1} & \cdots & \xi^{(\gamma,N)}_{n_{Y},M_{n_{Y}}} 
\end{pNiceArray}
\]


\setlength{\arraycolsep}{1pt}
\[
\begin{pNiceMatrix}
  %nicematrix
  \xi^{(\gamma,1)}_{1,1} & \cdots & \xi^{(\gamma,1)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,1)}_{n_{Y},1} & \cdots & \xi^{(\gamma,1)}_{n_{Y},M_{n_{Y}}} \\
  \Vdots                 &        &                             &         &                            &        & \vdots \\
  \xi^{(\gamma,N)}_{1,1} & \cdots & \xi^{(\gamma,N)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,N)}_{n_{Y},1} & \cdots & \xi^{(\gamma,N)}_{n_{Y},M_{n_{Y}}} 
\end{pNiceMatrix}
\]
\end{document}

Output of the above code

2

I found a first solution in this answer, but it reduces the width of each column not only the columns 2,4,6. This behavior is enough for my usage, and it maybe the only solution, as the environment pNiceMatrix is based on the amsmath environments {matrix} and {pmatrix}.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\setlength{\arraycolsep}{1pt}
\[
\begin{pNiceMatrix}
  %nicematrix
  \xi^{(\gamma,1)}_{1,1} & \cdots & \xi^{(\gamma,1)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,1)}_{n_{Y},1} & \cdots & \xi^{(\gamma,1)}_{n_{Y},M_{n_{Y}}} \\
  \Vdots                 &        &                             &         &                            &        & \vdots \\
  \xi^{(\gamma,N)}_{1,1} & \cdots & \xi^{(\gamma,N)}_{1,M_{1}}, & \Cdots  &, \xi^{(\gamma,N)}_{n_{Y},1} & \cdots & \xi^{(\gamma,N)}_{n_{Y},M_{n_{Y}}} 
\end{pNiceMatrix}
\]
\end{document}

Output :

enter image description here

You must log in to answer this question.

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