自 TeXLive 2021 起,`interfaces` 包中 `\repeatcell` 的替代品

自 TeXLive 2021 起,`interfaces` 包中 `\repeatcell` 的替代品

xelatex在 TeXLive 2020 及更早版本中编译时可以正确运行的 MWE :

\documentclass{ctexbook}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{interfaces-makecell}
\usepackage{CJKnumb}

\newcounter{ncolumns}
\setcounter{ncolumns}{5}

\begin{document}
    \begin{tabularx}{\textwidth}{*{\thencolumns}{|X<{\centering}}|}
        \hline
        \repeatcell{\thencolumns}{text = \CJKnumber{\c}} \\
        \hline
        \eline{\thencolumns} \\
        \hline
        \repeatcell{\thencolumns}{ff = $int(\c + \thencolumns)$, text = \CJKnumber{\ff}} \\
        \hline
        \eline{\thencolumns} \\
        \hline
    \end{tabularx}
\end{document}

正如评论中所解释的那样这个问题,该interfaces包自 TeXLive 2021 起不再受支持。那么,有没有其他方法可以得到与上述相同的结果,即生成具有特定列数的表格并在某些单元格中填充一系列数字?谢谢!

答案1

语法不一样,但我相信它仍然足够了。

\documentclass{ctexbook}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{CJKnumb}

\newcounter{ncolumns}
\setcounter{ncolumns}{5}

\ExplSyntaxOn
% we need LaTeX counters and not expl3 ones because of tabularx two-step process
\newcounter{repeatstart}
\newcounter{repeatcurrent}
\newcounter{repeatlast}

\NewDocumentCommand{\repeatcell}{mm}
 {% #1 = number of repeats
  % #2 = key-value pairs
  \oaheix_repeatcell:nn { #1 } { #2 }
 }

\tl_new:N \l__oaheix_repeatcells_body_tl

\keys_define:nn { oaheix/repeatcells }
 {
  text .code:n = \cs_gset_protected:Nn \__oaheix_repeatcell_text:n { #1 },
  start .code:n = \setcounter{repeatstart}{#1},
 }

\cs_new_protected:Nn \oaheix_repeatcell:nn
 {
  \keys_set:nn { oaheix/repeatcells } { #2 }
  \tl_clear:N \l__oaheix_repeatcells_body_tl
  \int_step_inline:nnn
   { \value{repeatstart} + 1 }
   { \value{repeatstart} + #1 }
   {
    \tl_put_right:Nx \l__oaheix_repeatcells_body_tl
     {
      \int_compare:nF { ##1 = \value{repeatstart} + 1 } { & }
      \__oaheix_repeatcell_text:n { ##1 }
     }
   }
  \tl_use:N \l__oaheix_repeatcells_body_tl
  \setcounter{repeatlast} { \int_eval:n { \value{repeatstart} + #1 } }
 }

\NewExpandableDocumentCommand{\lastvalue}{}{\int_eval:n { \value{repeatlast} } }

\AtBeginEnvironment{tabularx}{\setcounter{repeatstart}{0}}

\ExplSyntaxOff

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{*{\value{ncolumns}}{|X<{\centering}}|}
  \hline
  \repeatcell{\value{ncolumns}}{text = \CJKnumber{#1}} \\
  \hline
  \eline{\value{ncolumns}} \\
  \hline
  \repeatcell{\value{ncolumns}}{start=\lastvalue, text = \CJKnumber{#1}} \\
  \hline
  \eline{\value{ncolumns}} \\
  \hline
\end{tabularx}

\bigskip
% repeat to show the numbers are correct

\noindent
\begin{tabularx}{\textwidth}{*{\value{ncolumns}}{|X<{\centering}}|}
  \hline
  \repeatcell{\value{ncolumns}}{text = #1} \\
  \hline
  \eline{\value{ncolumns}} \\
  \hline
  \repeatcell{\value{ncolumns}}{start=\lastvalue, text = #1} \\
  \hline
  \eline{\value{ncolumns}} \\
  \hline
\end{tabularx}

\end{document}

在此处输入图片描述

请注意,不要使用\c当前列索引,而是使用#1。最后使用的值存储为\lastvalue

相关内容