3

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)

Cont-caption vs First Caption - longtblr (without vspace 1pt)

2
  • 1
    Can you please add a screenshot, so everybody can see the extra space you mention? Thank you
    – MS-SPO
    Commented Jan 6 at 17:38
  • 1
    @MS-SPO the space mismatch happens without vspace. Im trying to identify why it does appear, to try to correct it without using vspace. My main focus is to allow the use of singlespacing, onehalfspacing or doublespacing both on the caption format and the document as a whole. I added the image as you requested.
    – Mane32
    Commented Jan 6 at 18:20

1 Answer 1

0

The problem was I was using a incorrect template. Instead of conthead, I should have use conthead-text.

Corrected definition is:

\DefTblrTemplate{middlehead,lasthead}{default}{%
    \addtocounter{table}{-1}%
    \captionsetup{type=table}%
    \caption[]{\InsertTblrText{caption} \UseTblrTemplate{conthead-text}{default}}%
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .