4
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{>{\arabic{iRow}}cc>{\alph{iRow}}cc}[first-row]
    \multicolumn{1}{c}{}\Block{1-2}{Name} && \Block{1-2}{Country} & \\
    & George && France \\
    & John && Hellas \\
    & Paul && England \\
    & Nick && USA \\
\end{NiceTabular}
\end{document}

enter image description here

Questions

  1. Is my code ok?
  2. Is there a better code? (with nicematrix and without \multicolumn and first-row)
polyn
  • 5,614
  • 1
    How is the question in the title related to the code and image given? – daleif Apr 26 '22 at 11:26
  • @daleif, the code is my answer to the question but I would like an answer without the use of \multicolumn and first-row. – polyn Apr 26 '22 at 11:38

2 Answers2

5

The second NiceTabular reproduces the first without using \multicolumn or first-row.

a

\NRow will output the row number decremented by 1 from the second row forward. \ARow does the same with alphabetical output.

\documentclass{article}
\usepackage{nicematrix}

\begin{document} \begin{NiceTabular}{>{\arabic{iRow}}cc>{\alph{iRow}}cc}[first-row] \multicolumn{1}{c}{}\Block{1-2}{Name} && \Block{1-2}{Country} & \ & George && France \ & John && Hellas \ & Paul && England \ & Nick && USA \ \end{NiceTabular}

\bigskip

% *************************************************** added <<<<< \newcounter{iRowtmp} \newcommand{\NRow}{\ifnum\value{iRow} >1 \the\numexpr\value{iRow}-1\fi}
\newcommand{\ARow}{\ifnum\value{iRow} >1 \setcounter{iRowtmp}{\the\numexpr\value{iRow}-1} \alph{iRowtmp}\fi}

\begin{NiceTabular}{>{\NRow}cc>{\ARow}cc} \Block{1-2}{Name} & & \Block{1-2}{Country} & \ & George& & France \ & John & & Hellas \ & Paul & & England \ & Nick & & USA \ \end{NiceTabular}

\end{document}

Interesting bit (after @Alan Munn comment) : the \ARow command can be further simplified by suppressing the row number check as in

\newcommand{\ARow}{\setcounter{iRowtmp}{\the\numexpr\value{iRow}-1}\space\alph{iRowtmp}}    

It will still work on the first row (where \iRow-1=0} because \space\alph{<\iRow-1>} will produce only the white space.

Simon Dispa
  • 39,141
  • This can be made much more simple: your \Nrow macro should be ifnum\value{iRow}=0\else\arabic{iRow}\fi and this is only needed in the first column, i.e., you don't need your \Arow macro at all, not clear why, though :) – Alan Munn Apr 26 '22 at 18:31
  • Thank for your feedback! The \ARow is needed to output the third column in alph format. Both \NRow and \ARow decreases \iRow by 1. – Simon Dispa Apr 26 '22 at 19:29
  • Sorry, what I meant to say is that you don't need the conditional code in your \Arow macro; you still need it to format the counter. But you don't need to do any arithmetic on the counter at all with the code I suggested as long as you have the [first row] option specified. – Alan Munn Apr 26 '22 at 19:34
  • @Simon Dispa Thank you very much for your answer. – polyn Apr 27 '22 at 08:28
4

Simplifying Simon's answer, you can simply add a conditional to the first column row code:

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{>{\ifnum\value{iRow}=0\else\arabic{iRow}\fi}cc>{\alph{iRow}}cc}[first-row]
    & Name&& Country\\
    & George && France \\
    & John && Hellas \\
    & Paul && England \\
    & Nick && USA \\
\end{NiceTabular}
\end{document}

It's actually not clear to me why the conditional code is only required in the one of the column specifications (it doesn't matter whether it's in the first or second column specification; either way it will suppress the counter in that row for all columns).

output of code

Alan Munn
  • 218,180