1

Is there a way to use the caption style defined in the caption package for a longtblr?

To format table captions, I am using the caption package as follows:

\usepackage[
    hypcap=true,
    format=hang,
    font={footnotesize, sf},
    labelfont={bf},
    margin=0cm,
    aboveskip=8pt,
    singlelinecheck=off,
]{caption}

This works well for small tables (without page breaks / page continuation):

\begin{table}[!htbp]
    \captionsetup{type=table}
    \caption{A small table}
    \begin{tblr}{l X[r] X[r] X[r]}
        a & b & c & d \\
        a & b & c & d \\
        a & b & c & d \\
    \end{tblr}
\end{table}

However, the style is not used in my long table. I had a look into the tabularray documentation (Section 4.2.1), but all I was able to find, is related to the caption contents, not its style. According to the caption documentation (Introduction), caption does not deal with caption contents, but caption style only:

Please note that the caption package is only controlling the look & feel of the captions.

Is there a way to combine the longtblr environment with the caption style defined with the caption package?

The MWE is as follows:

\documentclass{article}

\usepackage{tabularray}

\usepackage[
    hypcap=true,
    format=hang,
    font={footnotesize, sf},
    labelfont={bf},
    margin=0cm,
    aboveskip=8pt,
    singlelinecheck=off,
]{caption}


\begin{document}

\begin{table}[!htbp]
    \captionsetup{type=table}
    \caption{A small table}
    \begin{tblr}{l X[r] X[r] X[r]}
        a & b & c & d\\
        a & b & c & d\\
        a & b & c & d \\
    \end{tblr}
\end{table}

\begin{longtblr}[
caption = A long table,
]{
    colspec = {l X X},
    rowhead = 1, rowfoot = 0,
}
    Head & Head & Head \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
    Alpha & Beta & Gamma \\
    Epsilon & Zeta & Eta \\
    Iota & Kappa & Lambda \\
    Nu & Xi & Omicron \\
    Rho & Sigma & Tau \\
    Phi & Chi & Psi \\
\end{longtblr}

\end{document}
1

2 Answers 2

1

The solution given in the link by Zarko works well in documents without a \listoftables. Once you want to have that list, you will end up with two entries of every table in it. Both the short caption (that should be in the list of tables) and the long version (that should only be used in the caption itself) are entered.

The tabularray package does not obey the options set in the caption package, as you (and I) noticed. But the package does have an extensive way to define themes that can be used to set the table caption in a desired way.

I use a coloured box in which the caption is typeset. Without going to create a whole MWE I just give the code snippets of the caption settings and of the (almost) equivalent tabularray theme settings.

My caption setup is defined as follows:

\usepackage{xcolor} 

     \definecolor{color2}{RGB}{255,255,120} % Color of the boxes behind the abstract and headings (dark yellow)
     \definecolor{color5}{RGB}{139,0,139} %Color of captions (dark purple)

\usepackage[labelfont={bf,sf,small,color=color5},%
     labelsep=endash,%
     box=colorbox,boxcolor=color2!10,slc=off,%
     textfont={color=color5},%
     justification=justified,%raggedright,%
     format=hang,indention=-15mm]{caption}
    \setlength{\abovecaptionskip}{0pt}
    \setlength{\belowcaptionskip}{0pt}

The tabularray theme derived from that is:

\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx,varwidth}

\DefTblrTemplate{caption-tag}{color}{\textcolor{color5}{\textsf{\textbf{Tabel \thetable}}}}
\DefTblrTemplate{caption-sep}{color}{\textcolor{color5}{\textbf{--}}}
\DefTblrTemplate{caption-text}{color}{\textcolor{color5}{\InsertTblrText{caption}}}
\DefTblrTemplate{caption-text}{colorcont}{\textcolor{color5}{\InsertTblrText{entry}}}
\DefTblrTemplate{conthead-text}{color}{\textcolor{color5}{(Vervolg)}}
\DefTblrTemplate{contfoot-text}{color}{\textcolor{color5}{\footnotesize Vervolg op volgende pagina}}

    \DefTblrTemplate{caption}{color}{
        \UseTblrTemplate{caption-tag}{color}
        \UseTblrTemplate{caption-sep}{color}
        \UseTblrTemplate{caption-text}{color}
    }
    
    \DefTblrTemplate{capcont}{color}{
        \UseTblrTemplate{caption-tag}{color}
        \UseTblrTemplate{caption-sep}{color}
        \UseTblrTemplate{caption-text}{colorcont}
        \UseTblrTemplate{conthead-text}{color}
    }
    
    \NewTblrTheme{colorcaps}{
        \SetTblrTemplate{caption}{color}
        \SetTblrTemplate{capcont}{color}
        \SetTblrTemplate{contfoot-text}{color}
        \SetTblrStyle{remark}{font=\footnotesize}
        \SetTblrStyle{note}{font=\footnotesize}
    }
    
    \usepackage{floatrow}
    \DeclareCaptionLabelSeparator{endash}{\textcolor{color5}{\enskip -- \space}}

As you see, the package floatrow provides the caption label separator to the theme. The one thing I still have trouble with is the hanging indentation. Otherwise using the theme colorcaps in tall/longtblr environments sets the caption according to \captionsetup and only the short entry is placed inside the \listoftables.

0

Just use this package:

\usepackage{tblr-caption}%Para alinear en formato APA 
\UseTblrLibrary{caption}

%% tblr-caption.sty
%% Copyright 2024 Manuel E. Merino
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Manuel E. Merino
%
\ProvidesPackage{tblr-caption}[2024/02/06 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}
}

You must log in to answer this question.

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