2

For a variety of reasons, I migrate some tabulars to NiceTabular. One of them looks like this:

\documentclass{article}

\makeatletter \newsavebox\saved@arstrutbox \newcommand{\setarstrut}[1]{% \noalign{% \begingroup \global\setbox\saved@arstrutbox\copy@arstrutbox #1% \global\setbox@arstrutbox\hbox{% \vrule @height\arraystretch\ht\strutbox @depth\arraystretch \dp\strutbox @width\z@ }% \endgroup }% } \newcommand{\restorearstrut}{% \noalign{% \global\setbox@arstrutbox\copy\saved@arstrutbox }% } \makeatother

\begin{document} \begin{tabular}{c@{/}c} \setarstrut{\tiny} \multicolumn{1}{c@{\tiny/}}{\tiny\textbf{droggel}} & \tiny\textbf{jug} \ \restorearstrut \hline 23 & 42 \end{tabular} \end{document}

The header is mostly taken from this answer about making rows smaller. What I do is that I render the first row smaller than the others. Since I use the separator character / between the columns, that should also be rendered smaller. To facilitate this, I add a \multicolumn that replaces the original separator with a tiny one.

Now I switch out tabular with NiceTabular:

\documentclass{article}
\usepackage{nicematrix}

\makeatletter \newsavebox\saved@arstrutbox \newcommand{\setarstrut}[1]{% \noalign{% \begingroup \global\setbox\saved@arstrutbox\copy@arstrutbox #1% \global\setbox@arstrutbox\hbox{% \vrule @height\arraystretch\ht\strutbox @depth\arraystretch \dp\strutbox @width\z@ }% \endgroup }% } \newcommand{\restorearstrut}{% \noalign{% \global\setbox@arstrutbox\copy\saved@arstrutbox }% } \makeatother

\begin{document} \begin{NiceTabular}{c@{/}c} \setarstrut{\tiny} \multicolumn{1}{c@{\tiny/}}{\tiny\textbf{droggel}} & \tiny\textbf{jug} \ \restorearstrut \hline 23 & 42 \end{NiceTabular} \end{document}

Compiling this yields:

! Package array Error: Empty preamble: `l' used.

See the array package documentation for explanation. Type H <return> for immediate help. ...

l.29 ...column{1}{c@{\tiny/}}{\tiny\textbf{droggel}} & \tiny\textbf{jug} \ \r...

The error comes from the @{\tiny/} bit of the multicolumn argument. If I delete this, the code renders but the / is obviously gone.

How can I migrate this properly to NiceTabular while keeping the separator setup?

flyx
  • 2,051
  • Your example code can be simplified/ shortened quite abit. \documentclass{article} \usepackage{nicematrix} \begin{document} \begin{NiceTabular}{cl} \multicolumn{1}{c@{}}{text} & text \\ text & text \end{NiceTabular} \end{document} for example still reproduces the error message you also get from your code. – leandriis Jun 09 '21 at 07:18
  • @leandriis Yeah I wanted to show some context so that someone can suggest a different approach to get what I want since I don't know the possibilities of NiceTabular that well. – flyx Jun 09 '21 at 10:18
  • 1
    (I'm the author of nicematrix). This is a problem of nicematrix. nicematrix is not compatible with all the types of format of \multicolumn. I should mention that problem in the documentation. Maybe, it will be solved in a future version. In your case, I would try to use a tabular with 3 columns (one for the /)... – F. Pantigny Jun 10 '21 at 20:37

1 Answers1

3

I have written a new version of nicematrix (v 5.17 of 2021-07-01). With that new version, the command \multicolumn should work as expected in the environments of nicematrix such as {NiceTabular}.

\documentclass{article}
\usepackage{nicematrix}

\makeatletter \newsavebox\saved@arstrutbox \newcommand{\setarstrut}[1]{% \noalign{% \begingroup \global\setbox\saved@arstrutbox\copy@arstrutbox #1% \global\setbox@arstrutbox\hbox{% \vrule @height\arraystretch\ht\strutbox @depth\arraystretch \dp\strutbox @width\z@ }% \endgroup }% } \newcommand{\restorearstrut}{% \noalign{% \global\setbox@arstrutbox\copy\saved@arstrutbox }% } \makeatother

\begin{document} \begin{NiceTabular}{c@{/}c} \setarstrut{\tiny} \multicolumn{1}{c@{\tiny/}}{\tiny\textbf{droggel}} & \tiny\textbf{jug} \ \restorearstrut \hline 23 & 42 \end{NiceTabular} \end{document}

Output of the above code

Zarko
  • 296,517
F. Pantigny
  • 40,250
  • With this version of nicematrix, having a tabular inside a \multicolumn in a NiceTabular creates an error while the previous version was able to process it (test code: \begin{NiceTabular}{p{5cm}}\multicolumn{1}{c}{\begin{tabular}{p{2cm}} foo \end{tabular}}\end{NiceTabular}). – flyx Jul 03 '21 at 21:47
  • @flyx: You're right. I have corrected that bug and I will post a new version of nicematrix on CTAN. However, if you want, I could sent you that new version and you could test it on your data (my email is on the documentation of nicematrix). – F. Pantigny Jul 04 '21 at 09:46
  • Thanks! I am pretty content that my input will be fine once the code fragment I showed works again, since I narrowed down the error source to that particular structure; everything else works. – flyx Jul 04 '21 at 10:22
  • @flyx: Perfect! I will post this new version on CTAN. – F. Pantigny Jul 04 '21 at 11:29