1

How can I build a table in several columns so that the numbering is automatic and the values in the table header are not numbered. You need to get a table in accordance with the figureenter image description here

    \documentclass[a4paper,12pt]{article}
\usepackage{cmap} 
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,russian]{babel} 
\usepackage{caption}
\usepackage{multirow}
\usepackage{array,etoolbox}
\usepackage{tikz}

\usepackage{siunitx}
\usepackage{nicematrix}

\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage[skip=1ex]{subcaption}

\usepackage{multicol}
\begin{document}
    \newcounter{rownum} 
    \setcounter{rownum}{-1}
    \newcommand{\Rownum}{\stepcounter{rownum} \ifnum\value{rownum}>0\relax\arabic{rownum}\fi }  

    \begin{table}[ht]
        \centering 
        \ExplSyntaxOn
        \NewDocumentCommand \BackgroundColors { }
        {
            \begin{tikzpicture}
                \begin{scope}
                    \clip [rounded~corners] (1-|1) rectangle (last-|last) ;
                    \fill [gray!40] (1-|1) rectangle (2-|last) ; 
                    \foreach \i in {3,5,7,...,\arabic{iRow}}
                    { \fill [gray!20] (\i-|1) rectangle (\int_eval:n{\i+1}-|last) ; }
                \end{scope}
                \draw [rounded~corners,gray!80] (1-|1) rectangle (last-|last) ; 
            \end{tikzpicture}
        }
        \ExplSyntaxOff
        \renewcommand{\arraystretch}{1.5}
        
        \begin{multicols}{2}
        \begin{NiceTabular}{>{\Rownum}cc}
            \CodeBefore
            \BackgroundColors
            \Body
            \RowStyle[bold]{}
            {\textnumero} & {F, MHz} \\
            & 433,075 \\
            & 433,100 \\
            & 433,125 \\
            & 433,155 \\
            & 433,175 \\
            & 433,200 \\    
            & 433,225 \\
            & 433,255 \\        
        \end{NiceTabular}
        \columnbreak
            \begin{NiceTabular}{>{\Rownum}cc}
        \CodeBefore
        \BackgroundColors
        \Body
        \RowStyle[bold]{}
        {\textnumero} & {F, MHz} \\
        & 433,075 \\
        & 433,100 \\
        & 433,125 \\
        & 433,155 \\
        & 434 \\
        & 435 \\    
        & 436 \\
        & 437 \\        
    \end{NiceTabular}
    \end{multicols}
    \end{table}

\end{document}

enter image description here

2
  • 1
    As a simple solution (and if you only have one header at the top of the table), you can do: \setcounter{rownum}{-1} and then: \newcommand{\Rownum}{\stepcounter{rownum} \ifnum\value{rownum}>0\relax\arabic{rownum}\fi }. Oct 31, 2022 at 9:30
  • Thanks, I fixed it, now my code looks like this. I was able to add a second column, but I couldn't get rid of the number in the table header again
    – Антон
    Oct 31, 2022 at 9:48

1 Answer 1

2

This is probably not the most elegant way to do this, but you can use a custom conditional that is set to false before the table header is typeset and then set to true via tha \Rownum macro. This will skip typesetting of the row number for the first row:

\documentclass[a4paper,12pt]{article}
\usepackage[english,russian]{babel} 
\usepackage{tikz}
\usepackage{nicematrix}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{multicol}

\begin{document}
    \newcounter{rownum} 
    \setcounter{rownum}{0}
    \newif\ifheadrow
    \newcommand{\Rownum}{\ifheadrow\stepcounter{rownum}\arabic{rownum}\fi}  

    \begin{table}[ht]
        \centering 
        \ExplSyntaxOn
        \NewDocumentCommand \BackgroundColors { }
        {
            \begin{tikzpicture}
                \begin{scope}
                    \clip [rounded~corners] (1-|1) rectangle (last-|last) ;
                    \fill [gray!40] (1-|1) rectangle (2-|last) ; 
                    \foreach \i in {3,5,7,...,\arabic{iRow}}
                    { \fill [gray!20] (\i-|1) rectangle (\int_eval:n{\i+1}-|last) ; }
                \end{scope}
                \draw [rounded~corners,gray!80] (1-|1) rectangle (last-|last) ; 
            \end{tikzpicture}
        }
        \ExplSyntaxOff
        \renewcommand{\arraystretch}{1.5}
        
        \begin{multicols}{2}
        \begin{NiceTabular}{>{\Rownum\global\headrowtrue}cc}
            \CodeBefore
            \BackgroundColors
            \Body
            \RowStyle[bold]{}
            {\textnumero} & {F, MHz} \\
            & 433,075 \\
            & 433,100 \\
            & 433,125 \\
            & 433,155 \\
            & 433,175 \\
            & 433,200 \\    
            & 433,225 \\
            & 433,255 \\        
        \end{NiceTabular}
        \columnbreak
        \global\headrowfalse
        \begin{NiceTabular}{>{\Rownum\global\headrowtrue}cc}
            \CodeBefore
            \BackgroundColors
            \Body
            \RowStyle[bold]{}
            {\textnumero} & {F, MHz} \\
            & 433,075 \\
            & 433,100 \\
            & 433,125 \\
            & 433,155 \\
            & 434 \\
            & 435 \\    
            & 436 \\
            & 437 \\        
        \end{NiceTabular}
        \end{multicols}
    \end{table}

\end{document}

enter image description here


You probably want to use multiple counters to be able to combine the different table columns into one single table:

\documentclass[a4paper,12pt]{article}
\usepackage[english,russian]{babel} 
\usepackage{tikz}
\usepackage{nicematrix}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{multicol}

\newcommand{\RownumCols}[2]{
    \newif\ifheadrow
    \global\headrowfalse
    \foreach \i in {1,...,#2} {
        \pgfmathparse{int(\i * #1 / #2 - #1 / #2)}
        \newcounter{rownum\romannumeral\i}
        \setcounter{rownum\romannumeral\i}{\pgfmathresult}
    }
}
\newcommand\Rownum[1]{
    \ifheadrow\stepcounter{rownum\romannumeral#1}\arabic{rownum\romannumeral#1}\fi
}

\begin{document}

    \begin{table}[ht]
        \centering 
        \ExplSyntaxOn
        \NewDocumentCommand \BackgroundColors { }
        {
            \begin{tikzpicture}
                \begin{scope}
                    \clip [rounded~corners] (1-|1) rectangle (last-|last) ;
                    \fill [gray!40] (1-|1) rectangle (2-|last) ; 
                    \foreach \i in {3,5,7,...,\arabic{iRow}}
                    { \fill [gray!20] (\i-|1) rectangle (\int_eval:n{\i+1}-|last) ; }
                \end{scope}
                \draw [rounded~corners,gray!80] (1-|1) rectangle (last-|last) ; 
            \end{tikzpicture}
        }
        \ExplSyntaxOff
        \renewcommand{\arraystretch}{1.5}
        
        \RownumCols{16}{2}
        
        \begin{NiceTabular}{>{\Rownum{1}}cc >{\Rownum{2}\global\headrowtrue}cc}
            \CodeBefore
            \BackgroundColors
            \Body
            \RowStyle[bold]{}
            {\textnumero} & {F, MHz} & {\textnumero} & {F, MHz} \\
            & 433,075 & & 433,075 \\
            & 433,100 & & 433,100 \\
            & 433,125 & & 433,125 \\
            & 433,155 & & 433,155 \\
            & 433,175 & & 434 \\
            & 433,200 & & 435 \\    
            & 433,225 & & 436 \\
            & 433,255 & & 437 \\        
        \end{NiceTabular}
    \end{table}

\end{document}

The macro \RownumCols{16}{2} takes the maximum count of entries and the number of columns. It sets up the needed counters that are already initialized with the correct starting value. You can access the value of these counters by using \Rownum{1} or \Rownum{2}.

enter image description here

3
  • Thanks. And the last question: how to align these two tables in the center and at the same time so that the distance between the tables is small?
    – Антон
    Oct 31, 2022 at 10:35
  • @Антон I don't quite understand what you mean. I guess, you want to make a four-column table out of the table? This, however, would require a totally different set-up. Oct 31, 2022 at 12:59
  • Perfect, this is what I need, thank you!
    – Антон
    Nov 1, 2022 at 13:40

You must log in to answer this question.

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