tabularray 패키지용 캡션 라이브러리

tabularray 패키지용 캡션 라이브러리

답변을 바탕으로 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의 첫 번째 캡션의 세로 간격과 계속되는 캡션 사이에 불일치가 발생합니다(첫 번째는 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}}%
}

관련 정보