- 我正在寻找一种方法来连续字幕使用不同的字幕文本。
middlehead
我认为这与and or相关,lasthead
但我不明白如何使用它。
\documentclass{article}
% "margin = 54mm" is used to control the page break for the MWE.
\usepackage[a4paper, margin = 54mm, landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{longtblr}[
caption = {First Caption},
% mid-caption = {Other Captions}, % <-- Pseudo Code :)
% last-caption = {Other Captions}, % <-- Pseudo Code :)
entry = {LoT Caption},
label = {tab:label};
]{
colspec = {t{0.20\linewidth}t{0.20\linewidth}t{0.20\linewidth}},
rowhead = 1,
row{1} = {font=\bfseries},
}
\toprule
A & B & C \\
\toprule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\
\bottomrule
\end{longtblr}
\end{document}
答案1
我不明白为什么你要在长表格的不同页面中使用不同的标题。这对我来说有点奇怪。但无论如何这是可行的:只需将两个标题添加到键中caption
,然后使用一些辅助命令检索它们。
\documentclass{article}
\usepackage[a6paper,top=35mm,bottom=35mm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\ExplSyntaxOn
\NewDocumentCommand\FirstOfTwo{m}{
\exp_last_unbraced:Ne \use_i:nn { #1 }
}
\NewDocumentCommand\SecondOfTwo{m}{
\exp_last_unbraced:Ne \use_ii:nn { #1 }
}
\ExplSyntaxOff
\DefTblrTemplate{caption-text}{first}{\FirstOfTwo{\InsertTblrText{caption}}}
\DefTblrTemplate{caption-text}{second}{\SecondOfTwo{\InsertTblrText{caption}}}
\DefTblrTemplate{firsthead}{default}{
\centering
\UseTblrTemplate{caption-tag}{default}
\UseTblrTemplate{caption-sep}{default}
\UseTblrTemplate{caption-text}{first}
\par
}
\DefTblrTemplate{middlehead,lasthead}{default}{
\centering
\UseTblrTemplate{caption-tag}{default}
\UseTblrTemplate{caption-sep}{default}
\UseTblrTemplate{caption-text}{second}
\par
}
\begin{document}
\begin{longtblr}[
caption = {First Caption}{Second Caption},
entry = {LoT Caption},
label = {tab:label};
]{
colspec = {t{0.2\linewidth}t{0.2\linewidth}t{0.2\linewidth}},
rowhead = 1,
row{1} = {font=\bfseries},
}
\toprule
A & B & C \\
\toprule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\
\bottomrule
\end{longtblr}
\end{document}
答案2
一种简单的方法是定义一个命令来对 和 的文本进行硬编码middlehead
。lasthead
使用命令\SetMidLastCaption
,您可以在“连续字幕”中放置任何您喜欢的文本。
显然,定义一个新键会更好,例如mid-caption
如您所建议的那样。但是,我不太熟悉expl3
,也许其他人可以提供帮助。
找到了解决方案,请参阅下面的编辑。
\documentclass{article}
% "margin = 54mm" is used to control the page break for the MWE.
\usepackage[a4paper, margin = 54mm, landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\ExplSyntaxOn
\NewDocumentCommand { \SetMidLastCaption }{ m }{
\DefTblrTemplate{ middlehead, lasthead }{ default }
{
\centering
#1
\par
}
}
\ExplSyntaxOff
% Use the following command to reset the captions to normal behaviour
%\SetTblrTemplate{middlehead,lasthead}{normal}
\begin{document}
\SetMidLastCaption{Other Captions}
\begin{longtblr}[
caption = {First Caption},
% mid-caption = {Other Captions}, % <-- Pseudo Code :)
entry = {LoT Caption},
label = {tab:label};
]{
colspec = {t{0.20\linewidth}t{0.20\linewidth}t{0.20\linewidth}},
rowhead = 1,
row{1} = {font=\bfseries},
}
\toprule
A & B & C \\
\toprule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\\midrule
a & b & c\\
\bottomrule
\end{longtblr}
\end{document}
编辑:新密钥的定义midlast-caption
以下代码将键定义midlast-caption
为 的外部键(用于可选参数)tblr
。分配应该是本地的,这意味着如果您不提供键,则标题应该使用模板normal
。如果您midlast-caption = {Other Captions}
在可选参数中使用,结果将与我的第一个示例相同。
\ExplSyntaxOn
\clist_gput_left:Nn \g__tblr_table_known_keys_clist { midlast-caption }
\keys_define:nn { tblr-outer } { midlast-caption .code:n = \__tblr_set_midlast_caption:n { #1 } }
\cs_new_protected:Npn \__tblr_set_midlast_caption:n #1 {
\DefTblrTemplate{ middlehead, lasthead }{ default }
{
\centering
#1
\par
}
}
\ExplSyntaxOff
免责声明我对 完全是新手expl3
。因此,此代码可能非常糟糕,请谨慎使用。我感谢所有改进此代码的人。