I am trying to (somewhat) implement a caption library for tabularray, based on the answer here
As @Ulrike mentioned, the original answer gives warnings with hyperref due to double hyperlinks anchors being defined, so I tried omitting one of the anchors for being generated.
Furthermore, I checked and I have to add an extra 1pt vspace for continued captions otherwise the vertical spacing between the first line of the table and the caption wouldn't match.
My question is: Where does the extra spacing comes from? Is adding the vspace command the best option to avoid it? And are there any other considerations that I am omitting?
\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 to test:
\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}
EDIT: Without the \vspace*{1pt} in tblr-caption I get a mismatch between the vertical spacing from the first caption of a longtblr and its continued caption as seen in the following picture (First is contcaption, second one is the main caption of a longtblr)

singlespacing,onehalfspacingordoublespacingboth on the caption format and the document as a whole. I added the image as you requested.