tabularray 套件的標題庫

tabularray 套件的標題庫

我正在嘗試(某種程度上)實現一個captiontabularray根據答案這裡

正如@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 的第一個標題與其連續標題的垂直間距不匹配,如下圖所示(第一個是 contcaption,第二個是 longtblr 的主標題)

連續字幕與第一個字幕 - longtblr(無 vspace 1pt)

答案1

問題是我使用了不正確的模板。相反conthead,我應該有用conthead-text

更正後的定義是:

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

相關內容