Nicematrix errors with aastex631

aastexnicematrixtables

Summary of Error

I am trying to use nicematrix in a AASTeX v6.3.1 LaTeX document. However, I get several errors such as "Missing number, treated as zero."

Any suggestions on how I can use nicematrix with AAStex?

Tex file using AASTex

\documentclass[ApJL,twocolumn]{aastex631}
\usepackage{aas_macros}
% \documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{nicematrix}

\begin{document}

\begin{table}[]
    \centering
    \begin{NiceTabular}{cc}
    \hline
    Writer & \Block[l]{}{year\\ of birth} \\
    \hline
    Hugo & 1802 \\
    Balzac & 1799 \\
    \hline
    \end{NiceTabular}
\end{table}

\end{document}

Error log summary

‪main.tex, 18‬
Package array Error: Illegal pream-token ([): `c' used.

‪main.tex, 23‬
Missing number, treated as zero.

‪main.tex, 23‬
Illegal unit of measure (pt inserted).

‪main.tex, 23‬
Missing number, treated as zero.

‪main.tex, 23‬
Illegal unit of measure (pt inserted).

Tex file without AASTex

% \documentclass[ApJL,twocolumn]{aastex631}
% \usepackage{aas_macros}
\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{nicematrix}

\begin{document}

\begin{table}[]
    \centering
    \begin{NiceTabular}{cc}
    \hline
    Writer & \Block[l]{}{year\\ of birth} \\
    \hline
    Hugo & 1802 \\
    Balzac & 1799 \\
    \hline
    \end{NiceTabular}
\end{table}

\end{document}

Compiled doc (without AASTex)

compiled doc

Best Answer

The latest version of nicematrix (v. 6.2 of 2021-09-09) is compatible with the class aastex631.

More precisely, that version is compatible with the class revtex-4.1 which is used by aastex631 (even though revtex-4.1 is obsolete and should be replaced by revtex-4.2). The class revtex-4.1 redefines {array} (of the eponymous package) and nicematrix (in the latest version) adds code to come back to the standard definition of array before using {array}.

However, there are, in fact, some lines of code to add in the preamble when using nicematrix with aastex631:

\BeforeBegin{NiceTabular}{\let\begin\BeginEnvironment\let\end\EndEnvironment}
\BeforeBegin{NiceArray}{\let\begin\BeginEnvironment}
\BeforeBegin{NiceMatrix}{\let\begin\BeginEnvironment}

Here is an example.

\documentclass[ApJL,twocolumn]{aastex631}
% \usepackage{aas_macros}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{nicematrix} % at least version 6.2 (2021-09-09)


\BeforeBegin{NiceTabular}{\let\begin\BeginEnvironment\let\end\EndEnvironment}
\BeforeBegin{NiceArray}{\let\begin\BeginEnvironment}
\BeforeBegin{NiceMatrix}{\let\begin\BeginEnvironment}


\begin{document}

\begin{table}[h]
    \centering
    \begin{NiceTabular}{cc}
    \hline
    Writer & \Block[l]{}{year\\ of birth} \\
    \hline
    Hugo & 1802 \\
    Balzac & 1799 \\
    \hline
    \end{NiceTabular}
\end{table}

\end{document}

Output of the above code