我刚刚发现表格数组我喜欢它。
使用键来参数化我的(x300)表变得非常简单。
然而,我遗漏了文档中的一些内容。
我们可以定义
\NewTblrTheme{fancy}{
\DefTblrTemplate{conthead}{default}{[Continued]}
\SetTblrStyle{firsthead}{font=\bfseries}
\SetTblrStyle{firstfoot}{fg=blue2}
\SetTblrStyle{middlefoot}{\itshape}
\SetTblrStyle{caption-tag}{red2}}
了解可以通过调用使用的表的一些功能[theme = fancy]
。
但是我怎样才能为其他元素创建一些东西(比如样式)
mystyle1/.style = {
colspec = {rX[c]X[c]X[c]},
width = 0.75\linewidth,
row{1} = {font=\bfseries},
column{1} = {font=\bfseries},
row{odd} = {green!10},
row{even} = {green!20},
}
mystyle2/.style = {
colspec = {rXXX},
width = \linewidth,
% row{1} = {font=\bfseries},
% column{1} = {font=\bfseries},
row{odd} = {blue!10},
row{even} = {blue!20},
}
\toprule
我还可以在此风格中控制、\midrule
和的行为吗\bottomrule
?
平均能量损失
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{longtblr}{ %mystyle1 %mystyle2
colspec = {rX[c]X[c]X[c]},
width = 0.75\linewidth,
row{1} = {font=\bfseries},
column{1} = {font=\bfseries},
row{odd} = {green!10},
row{even} = {green!20},
}
\toprule
& S\&P & Fitch & Moody's \\
\midrule
Prime & AAA & AAA & Aaa \\
\multirow{3}{*}{High grade} & AA+ & AA+ & Aa1 \\
& AA & AA & Aa2 \\
& AA- & AA- & Aa3 \\
\multirow{3}{*}{Upper medium grade} & A+ & A+ & A1 \\
& A & A & A2 \\
& A- & A- & A3 \\
\multirow{3}{*}{Lower medium grade} & BBB+ & BBB+ & Baa1 \\
& BBB & BBB & Baa2 \\
& BBB- & BBB- & Baa3 \\
\bottomrule
\end{longtblr}
\end{document}
答案1
您可以使用\NewTblrEnviron
来定义一个新的环境,并使用\SetTblrInner
来设置默认样式:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\NewTblrEnviron{mytblr}
\SetTblrOuter[mytblr]{long}
\SetTblrInner[mytblr]{
colspec = {rX[c]X[c]X[c]},
width = 0.85\linewidth,
row{1} = {font=\bfseries},
column{1} = {font=\bfseries},
row{odd} = {green!10},
row{even} = {green!20},
rowhead = 1,
hline{1,Z} = {0.08em}, % toprule and bottomrule
hline{2} = {0.05em}, % midrule
}
\begin{document}
\begin{mytblr}[
caption = {My Caption},
]{
% more specs
}
& S\&P & Fitch & Moody's \\
Prime & AAA & AAA & Aaa \\
\SetCell[r=3]{r}High grade & AA+ & AA+ & Aa1 \\
& AA & AA & Aa2 \\
& AA- & AA- & Aa3 \\
\SetCell[r=3]{r}Upper medium grade & A+ & A+ & A1 \\
& A & A & A2 \\
& A- & A- & A3 \\
\SetCell[r=3]{r}Lower medium grade & BBB+ & BBB+ & Baa1 \\
& BBB & BBB & Baa2 \\
& BBB- & BBB- & Baa3 \\
\end{mytblr}
\end{document}
答案2
第二版(更好的名称和错误信息)
使用\DefTblrInnerStyle
宏定义样式(本地)。要应用定义的样式,请使用环境style
强制参数中的键tblr
。
\documentclass{standalone}
\usepackage{xcolor}
\usepackage{tabularray}
\pagestyle{empty}
\ExplSyntaxOn
\clist_gput_left:Nn \g__tblr_table_known_keys_clist { style }
\keys_define:nn { tblr } { style .code:n = \__tblr_apply_style:n { #1 } }
\msg_new:nnn { tblr } { undefined inner style } { undefined ~ tblr ~ inner ~ style ~ '#1' ! }
\cs_new_protected:Npn \__tblr_apply_style:n #1 {
\tl_if_exist:cTF { l__tblr_inner_style_ #1 _tl } {
\keys_set:nv { tblr } { l__tblr_inner_style_ #1 _tl }
} {
\msg_error:nnn { tblr } { undefined inner style } { #1 }
}
}
\NewDocumentCommand \DefTblrInnerStyle { m m } {
\tl_clear_new:c { l__tblr_inner_style_ #1 _tl }
\tl_set:cx { l__tblr_inner_style_ #1 _tl } { #2 }
}
\ExplSyntaxOff
\begin{document}
\DefTblrInnerStyle{test 1}{row{1}={r,bg=blue!50},column{2}={fg=red}}
\DefTblrInnerStyle{test 2}{row{1}={l,bg=lime},column{2}={fg=blue}}
\DefTblrInnerStyle{test 3}{style=test 1,style=test 2}
{
\DefTblrInnerStyle{test 3}{style=test 2,style=test 1}
\begin{tblr}{colspec={ccc},style=test 3,hlines,vlines}
abbb & b & c \\
a & baba & cdsdd
\end{tblr}
}
\begin{tblr}{colspec={ccc},style=test 3,hlines,vlines}
abbb & b & c \\
a & baba & cdsdd
\end{tblr}
\end{document}