基于tabularray的一个自动化方案...
\documentclass{article}
\usepackage{fourier}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{functional}
\IgnoreSpacesOn
\prgNewFunction \makeHundredCells { } {
\tlSet \lTmpaTl { }
\intStepOneInline {1} {100} {
\intCaseF { ##1 } {
{ 2 } { }
{ 3 } { }
{ 5 } { }
{ 7 } { }
} {
\intCompareTF { \intMathMod{##1}{2} } = { 0 } {
\tlPutRight \lTmpaTl { \SetCell{bg=magenta!50} }
}{
\intCompareTF { \intMathMod{##1}{3} } = { 0 } {
\tlPutRight \lTmpaTl { \SetCell{bg=cyan!50} }
}
{
\intCompareTF { \intMathMod{##1}{5} } = { 0 } {
\tlPutRight \lTmpaTl { \SetCell{bg=violet!50} }
}
{
\intCompareT { \intMathMod{##1}{7} } = { 0 } {
\tlPutRight \lTmpaTl { \SetCell{bg=orange!50} }
}
}
}
}
}
\intCompareTF { ##1 } = { 1 } {
\tlPutRight \lTmpaTl { }
}{
\tlPutRight \lTmpaTl { ##1 }
}
\intCompareTF { \intMathMod{##1}{10} } = { 0 } {
\tlPutRight \lTmpaTl { \\ }
}{
\tlPutRight \lTmpaTl { & }
}
}
\prgReturn { \expValue \lTmpaTl }
}
\IgnoreSpacesOff
\begin{document}
\begin{tblr}[evaluate=\makeHundredCells]{
colspec = {*{10}{X[c]}},
hlines, vlines,
rows = {m, ht=3em},
}
\makeHundredCells
\end{tblr}
\end{document}或者等价的,用逻辑划分更清晰的evaluate = \makeTableBody和process = \myTblrProcessor分别控制内容和样式
\documentclass{article}
\usepackage{fourier}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{functional}
\IgnoreSpacesOn
\tlNew \lBodyTl
\tlNew \lCellValueTl
\prgNewFunction \makeTableBody { } {
\tlClear \lBodyTl
\intStepOneInline {1} {100} {
\tlPutRight \lBodyTl { ##1 }
\intCompareTF { \intMathMod{##1}{10} } = { 0 } {
\tlPutRight \lBodyTl { \\ }
}{
\tlPutRight \lBodyTl { & }
}
}
\prgReturn { \expValue \lBodyTl }
}
\prgNewFunction \myTblrProcessor { } {
\intStepOneInline {1} {\arabic{rowcount}} {
\intStepOneInline {1} {\arabic{colcount}} {
\tlSet \lCellValueTl { \cellGetText {##1} {####1} }
\intCompareT { \lCellValueTl } = { 1 } {
\cellSetText {##1} {####1} { }
}
\intCaseF { \lCellValueTl } {
{ 2 } { } { 3 } { } { 5 } { } { 7 } { }
} {
\intCompareTF { \intMathMod{\lCellValueTl}{2} } = { 0 } {
\cellSetStyle {##1} {####1} { bg=magenta!50 }
}{
\intCompareTF { \intMathMod{\lCellValueTl}{3} } = { 0 } {
\cellSetStyle {##1} {####1} { bg=cyan!50 }
}{
\intCompareTF { \intMathMod{\lCellValueTl}{5} } = { 0 } {
\cellSetStyle {##1} {####1} { bg=violet!50 }
}{
\intCompareT { \intMathMod{\lCellValueTl}{7} } = { 0 } {
\cellSetStyle {##1} {####1} { bg=orange!50 }
}
}
}
}
}
}
}
}
\IgnoreSpacesOff
\begin{document}
\begin{tblr}[
evaluate = \makeTableBody
]{
colspec = {*{10}{X[c]}},
hlines, vlines,
rows = {m, ht=3em},
process = \myTblrProcessor
}
\makeTableBody
\end{tblr}
\end{document}






















问 一个趣味循环编程练习