我正在尝试(某种程度上)根据答案实现一个caption
库tabularray
这里
正如@Ulrike 提到的,原始答案由于hyperref
定义了双超链接锚点而发出警告,因此我尝试省略其中一个要生成的锚点。
此外,我检查了一下,我必须为连续的标题添加额外的 1pt vspace,否则表格第一行和标题之间的垂直间距将不匹配。
我的问题是:额外的间距从何而来?添加 vspace 命令是避免它的最佳选择吗?我还忽略了其他什么考虑因素吗?
\ProvidesPackage{tblr-caption}[2024/01/02 package tblr-caption]
\RequirePackage{tabularray}
\RequirePackage{caption}
\@ifundefined{KOMAClassName}
{}
{\PackageWarningNoLine{tblr-caption}{KOMAScript class detected. Setup caption position using 'captions=<option>'}}
\@ifpackageloaded{hyperref}{%
\newenvironment{nohyp}{\begin{NoHyper}}{\end{NoHyper}}
}{%
\newenvironment{nohyp}{}{}
}
\ExplSyntaxOn
\prg_generate_conditional_variant:Nnn \tl_if_empty:n { e } { TF }
\let \IfTokenListEmpty = \tl_if_empty:eTF
\ExplSyntaxOff
\NewTblrLibrary{caption}
{%
\SetTblrOuter[talltblr,longtblr]{headsep=0pt}
\DefTblrTemplate{firsthead}{default}{%
\addtocounter{table}{-1}%
\IfTokenListEmpty{\InsertTblrText{entry}}{%
\begin{nohyp}%
\captionsetup{type=table}
\caption{\InsertTblrText{caption}}%
\end{nohyp}%
}{%
\begin{nohyp}%
\captionsetup{type=table}
\caption[\InsertTblrText{entry}]{\InsertTblrText{caption}}%
\end{nohyp}%
}%
}
\DefTblrTemplate{middlehead,lasthead}{default}{%
\addtocounter{table}{-1}%
\captionsetup{type=table}%
\caption[]{\InsertTblrText{caption} \UseTblrTemplate{conthead}{default}}
\vspace*{1pt}%
}
\SetTblrTemplate{caption-lot}{empty}
}
MWE 测试:
\documentclass[12pt]{article}
\usepackage[spanish,mexico]{babel}
\usepackage{lipsum}
\usepackage[singlespacing]{setspace}
\usepackage{tabularray}
\usepackage{hyperref} %% must be loaded for tblr-caption to work
\usepackage{tblr-caption} %% must be loaded after hyperref
\UseTblrLibrary{caption}
\captionsetup[table]{%
format=plain,
labelsep = newline,
singlelinecheck = false,
labelfont = bf,
textfont = it,
font = {small,singlespacing},
position = above,
}%
\DefTblrTemplate{conthead-text}{default}{(Continuación)}
\DefTblrTemplate{contfoot-text}{default}{Continúa en la siguiente página}
\begin{document}
\section{Introduction}
\begin{table}[htbp]
\centering
\captionsetup{width=5cm}
\caption{caption using tabular and caption package}
\begin{tabular}{|c|c|c|c|}
\hline
a & b & filler text & filler text\\
\hline
a & b & filler text & filler text\\
\hline
a & b & filler text & filler text\\
\hline
a & b & filler text & filler text\\
\hline
\end{tabular}
\label{tab:my_label}
\end{table}
\begin{table}[htbp]
\centering
\begin{talltblr}[caption={caption using tabularray package}]{colspec={cccc},hline{1,2,Z} = {0.05em}}
a & b & filler text & filler text\\
a & b & filler text & filler text\\
a & b & filler text & filler text\\
a & b & filler text & filler text\\
\end{talltblr}
\end{table}
\begin{longtblr}[
caption = {The Caption of {\ttfamily longtblr} environment.},
entry = {The Caption in LOT},
label=table1,
% headsep=0pt,
]{
colspec = {rccl},
hline{1,2,Z} = {0.05em},
row{1} = {font=\bfseries},
rowhead = 1,
}
date & time & time zone & event \\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
2019/01/01 & 00:00 & CET & server installation finished\\
2019/01/01 & 00:05 & CET & server successfully booted\\
2019/01/01 & 00:06 & CET & starting xyz daemon\\
\end{longtblr}
\end{document}
编辑:如果没有\vspace*{1pt}
in,tblr-caption
我得到的 longtblr 的第一个标题和它的连续标题之间的垂直间距不匹配,如下图所示(第一个是连续标题,第二个是 longtblr 的主标题)
答案1
问题是我使用了错误的模板。conthead
我应该使用 ,而不是conthead-text
。
更正后的定义是:
\DefTblrTemplate{middlehead,lasthead}{default}{%
\addtocounter{table}{-1}%
\captionsetup{type=table}%
\caption[]{\InsertTblrText{caption} \UseTblrTemplate{conthead-text}{default}}%
}