是否可以为所有表格创建全局样式?例如:
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor,colortbl}
\usepackage{multirow}
\usepackage{hhline}
\definecolor{rowcol}{rgb}{0.7, 0.7, 0.7}
\usepackage{tabularray}
\title{Example}
\author{Anon}
\date{May 2023}
\begin{document}
\maketitle
\section{Introduction}
\begin{table}[h]
\centering
\begin{tblr}{
colspec={X[c,m]Q[c,m]Q[c,m]Q[c,m]Q[c,m]},
cells={font=\large},
cell{1}{1} = {r=2}{c},
cell{1}{1} = {c=1}{c},
cell{1}{2} = {c=4}{c},
hlines,
hline{1-Z}={1}{1}{leftpos=1, rightpos=0.15},
hline{1-Z}={1}{2}{leftpos=0.15, rightpos=1},
hline{3}={2}{-}{solid},
hline{3}={2}{1}{leftpos=1, rightpos=0.15},
hline{3}={2}{2}{leftpos=0.15, rightpos=1},
vlines,
vline{2}={2}{-}{},
row{odd[3]}={bg=rowcol}
}
& Description \\
& 1 & 2 & 3 & 4 \\
A & 10 & 20 & 30 & 40 \\
B & 15 & 25 & 35 & 25 \\
C & 12 & 22 & 32 & 80 \\
\end{tblr}
\caption{Table 1}
\label{lbl1}
\end{table}
\begin{table}[h]
\centering
\begin{tblr}{
colspec={X[c,m]Q[c,m]Q[c,m]Q[c,m]Q[c,m]},
cells={font=\large},
cell{1}{1} = {r=2}{c},
cell{1}{1} = {c=1}{c},
cell{1}{2} = {c=4}{c},
hlines,
hline{1-Z}={1}{1}{leftpos=1, rightpos=0.15},
hline{1-Z}={1}{2}{leftpos=0.15, rightpos=1},
hline{3}={2}{-}{solid},
hline{3}={2}{1}{leftpos=1, rightpos=0.15},
hline{3}={2}{2}{leftpos=0.15, rightpos=1},
vlines,
vline{2}={2}{-}{},
row{odd[3]}={bg=rowcol}
}
& Description \\
& 1 & 2 & 3 & 4 \\
A & 10 & 20 & 30 & 40 \\
B & 15 & 25 & 35 & 25 \\
C & 12 & 22 & 32 & 80 \\
\end{tblr}
\caption{Table 2}
\label{lbl2}
\end{table}
\end{document}
这里只有两个表,但是当表很多时,每次都必须复制这些精确的设置,这样看起来不太美观,而且当您想要调整某些内容时需要进行许多更改。拥有一种全局样式会更好。但我找不到如何做到这一点的明确答案。
答案1
您可以创建自定义tblr
按照第 3.4 节“新 Tabularray 环境”中的说明创建自定义环境tabularray
手动的就像这样(第二个表中的红线只是为了表明始终可以覆盖规范):
\documentclass{article}
\usepackage{xcolor, tabularray}
\definecolor{rowcol}{rgb}{0.7, 0.7, 0.7}
\begin{document}
\NewTblrEnviron{mytblr}
\SetTblrInner[mytblr]{
colspec={X[c,m]Q[c,m]Q[c,m]Q[c,m]Q[c,m]},
cells={font=\large},
cell{1}{1}={r=2}{c},
cell{1}{1}={c=1}{c},
cell{1}{2}={c=4}{c},
hlines,
hline{1-Z}={1}{1}{leftpos=1, rightpos=0.15},
hline{1-Z}={1}{2}{leftpos=0.15, rightpos=1},
hline{3}={2}{-}{solid},
hline{3}={2}{1}{leftpos=1, rightpos=0.15},
hline{3}={2}{2}{leftpos=0.15, rightpos=1},
vlines,
vline{2}={2}{-}{},
row{odd[3]}={bg=rowcol}
}
\section{Introduction}
\begin{table}[h]
\centering
\begin{mytblr}{}
& Description \\
& 1 & 2 & 3 & 4 \\
A & 10 & 20 & 30 & 40 \\
B & 15 & 25 & 35 & 25 \\
C & 12 & 22 & 32 & 80 \\
\end{mytblr}
\caption{Table 1}
\label{lbl1}
\end{table}
\begin{table}[h]
\centering
\begin{mytblr}{
hlines={red}
}
& Description \\
& 1 & 2 & 3 & 4 \\
A & 10 & 20 & 30 & 40 \\
B & 15 & 25 & 35 & 25 \\
C & 12 & 22 & 32 & 80 \\
\end{mytblr}
\caption{Table 2}
\label{lbl2}
\end{table}
\end{document}