tabularray パッケージのキャプション ライブラリ

tabularray パッケージのキャプション ライブラリ

私は答えに基づいて、 (ある程度)captionのライブラリを実装しようとしていますtabularrayここ

@Ulrike が述べたように、元の回答では、hyperref二重のハイパーリンク アンカーが定義されているために警告が表示されるため、生成されるアンカーの 1 つを省略してみました。

さらに、確認したところ、キャプションが続く場合は 1 ポイントの 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、2 番目は 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}}%
}

関連情報