1

A MWE which runs correctly when compiled with xelatex in TeXLive 2020 and older:

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

As explained in the comments under this question, the interfaces package is not supported since TeXLive 2021. So, is there any alternative way to give the same result as above, i.e. to generate a table with a specific number of columns and fill a series of numbers in some cells? Thanks!

1 Answer 1

1

Not the same syntax, but I believe it's sufficient nonetheless.

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

enter image description here

Note you don't use \c for the current column index, but rather #1. The last value used is stored as \lastvalue.

1
  • Thank you very much! That's just what I want.
    – oaheix
    Commented Dec 8, 2021 at 6:19

You must log in to answer this question.

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