具有行自动编号的多列表格

具有行自动编号的多列表格

如何构建一个多列表格,以便自动编号,并且表格标题中的值不编号。您需要获取与图一致的表格在此处输入图片描述

    \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}

在此处输入图片描述

答案1

这可能不是最优雅的方法,但您可以使用自定义条件,在表头排版之前将其设置为 false,然后通过该\Rownum宏将其设置为 true。这将跳过第一行的行号排版:

\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}

在此处输入图片描述


您可能希望使用多个计数器来将不同的表列组合成一个表:

\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}

该宏\RownumCols{16}{2}采用最大条目数和列数。它设置已使用正确的起始值初始化的所需计数器。您可以使用\Rownum{1}或访问这些计数器的值\Rownum{2}

在此处输入图片描述

相关内容