我需要一个宏来在表中创建条目(行)。如提议的那样这里我成功地将这个environ
包与那个包一起使用tabu
。由于tabu
没有维护,我决定切换到tabularray
这个包。
不幸的是,tabularray
使用宏并不容易。我尝试将命令传递\BODY
给expand
选项,但没有成功:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{environ}
\NewEnviron{tabletest}{
\begin{tblr}[expand=\BODY]
{colspec = {X[6,l,m]X[1,c,m]X[0.5,c,m]X[1,r,m]},
rowsep = {3mm},
rowhead = 1, rowfoot = 1,
row{odd} = {gray!20}, row{even} = {gray!5},
row{Z} = {gray} % last line
}
\SetRow{12mm, c, bg=gray, font=\large\bfseries} Title & A & B & C \\
\BODY
This & is & last & row \\
\end{tblr}
}
\newcommand{\addrow}[4]{#1 & #2 & #3 & #4 \\}
\begin{document}
\begin{tabletest}
This & is & a & line \\
This & is & a & line \\
% \addrow{This}{is}{a}{test} <-- not working !
\end{tabletest}
\end{document}
我想用\addrow
宏创建所有线条。我该怎么做?谢谢您的帮助。
答案1
类似这样的事情可能会有效:
\documentclass[a4paper,10pt]{article}
\usepackage{xcolor}
\usepackage{tabularray}
\NewDocumentEnvironment{tabletest}{+b}
{
\begin{tblr}[expand=\addrow]
{colspec = {X[6,l,m]X[1,c,m]X[0.5,c,m]X[1,r,m]},
rowsep = {3mm},
rowhead = 1, rowfoot = 1,
row{odd} = {gray!20}, row{even} = {gray!5},
row{Z} = {gray} % last line
}
\SetRow{12mm, c, bg=gray, font=\large\bfseries} Title & A & B & C \\
#1
This & is & last & row \\
\end{tblr}
}{}
\newcommand{\addrow}[4]{#1 & #2 & #3 & #4 \\}
\begin{document}
\begin{tabletest}
This & is & a & line \\
This & is & a & line \\
\addrow{This}{is}{a}{test}
\end{tabletest}
\end{document}