pgfplotstable 与新命令之间的交互

pgfplotstable 与新命令之间的交互

我正在尝试生成一个大表,其中包含来自我生成的外部 csv 文件的信息。我不太明白以下代码中发生了什么。我定义了这个新命令:

\ExplSyntaxOn
\NewDocumentCommand \IfStringInList {mmmm} {\ExpandArgs{ee}
  \clist_if_in:nnTF {#1} {#2} {#3} {#4} }
\ExplSyntaxOff

\newcommand{\abacus}[2]{%
  \def\mylist{#2}% Convert the comma-separated list to an array
  \def\maxvalue{0}
  \foreach \element in \mylist {%
    \IfInteger{\element}{%
      \ifnum\element>\maxvalue
        \xdef\maxvalue{\element}%
      \fi
    }{}%
  }%
  \def\mytablecontents{}%
  \FPeval{\nbcolc}{clip(#1-1)}%
  \FPeval{\nblinc}{clip(trunc(\maxvalue/#1:0)+1)}%
  %\def\nblinc{\xintexpr{floor(\nblincnint)}}
  \foreach \i in {1,..., \nblinc}{%
     \foreach \j in {0,...,\nbcolc}{%
        \FPeval{\res}{clip((\nbcolc+1)*(\i-1)+\j)}
        % Check if \res is in the array using \IfSubStr
    \IfStringInList{\mylist}{\res}{%
          \xappto\mytablecontents{\fbox{$\res$} &}%
        }{%
          \xappto\mytablecontents{$\res$ &}%
        }%
     }%
     \gappto\mytablecontents{\\}%
  }%
  \FPeval{\nbcolt}{clip(#1+1)}%
  \begin{tabular}{r *{\nbcolt}{c}}%
     \mytablecontents%
   \end{tabular}%
}

此命令需要包 pgffor、etoolbox、fp、xstring 才能正常工作。为了生成我的大表,我使用了 pgfplotstable、colortbl、booktabs。这是一个最小示例:

\documentclass{article}
\usepackage{pgffor,etoolbox}
\usepackage{fp}
\usepackage{xstring}

\ExplSyntaxOn
\NewDocumentCommand \IfStringInList {mmmm} {\ExpandArgs{ee}
  \clist_if_in:nnTF {#1} {#2} {#3} {#4} }
\ExplSyntaxOff

\newcommand{\abacus}[2]{%
  \def\mylist{#2}% Convert the comma-separated list to an array
  \def\maxvalue{0}
  \foreach \element in \mylist {%
    \IfInteger{\element}{%
      \ifnum\element>\maxvalue
        \xdef\maxvalue{\element}%
      \fi
    }{}%
  }%
  \def\mytablecontents{}%
  \FPeval{\nbcolc}{clip(#1-1)}%
  \FPeval{\nblinc}{clip(trunc(\maxvalue/#1:0)+1)}%
  %\def\nblinc{\xintexpr{floor(\nblincnint)}}
  \foreach \i in {1,..., \nblinc}{%
     \foreach \j in {0,...,\nbcolc}{%
        \FPeval{\res}{clip((\nbcolc+1)*(\i-1)+\j)}
        % Check if \res is in the array using \IfSubStr
    \IfStringInList{\mylist}{\res}{%
          \xappto\mytablecontents{\fbox{$\res$} &}%
        }{%
          \xappto\mytablecontents{$\res$ &}%
        }%
     }%
     \gappto\mytablecontents{\\}%
  }%
  \FPeval{\nbcolt}{clip(#1+1)}%
  \begin{tabular}{r *{\nbcolt}{c}}%
     \mytablecontents%
   \end{tabular}%
}

\usepackage[usestackEOL]{stackengine}
\usepackage[landscape, a3paper, left=0mm, top=0mm, bottom=0mm, right=0mm, margin=0mm]{geometry}
\usepackage[english]{babel} % for french
\usepackage[T1]{fontenc} % for accents
\usepackage{mathtools, amsthm, stmaryrd, eufrak} % maths packages
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage{comment}
\usepackage{booktabs}
\usepackage{multicol}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{table}
\centering
\abacus{3}{2,4,5}
\end{table}
\end{document}

它无法编译,我不太明白为什么。当我注释掉 pgfplotstable、colortbl、booktabs 时...

有人能解释一下发生了什么吗?提前谢谢,Rhylx

相关内容