1

I am writing a longer document divided into \frontmatter and \mainmatter using the scrbook class. While both a table caption and a LOT entry should be generated for tables provided in the mainmatter, both items need be omitted/suppressed for tables given in the frontmatter (think e.g. list of abbreviations, list of symbols ...).

Furthermore, to have consistent caption formatting for tables, figures, listings etc., I decided to rely on the caption package.

Using the caption package to format the caption of tabularray tables as been elaborated in several places like:

Similarily, creating tables without caption and LOT entry is described in multiple instances:

If you write entry=none, tabularray package will not add an entry in List of Tables. Therefore caption=text,entry=none is similar to \caption[]{text} in longtable. If you write label=none, tabularray package will not step table counter, and set the caption-tag and caption-sep elements (see below) to empty. Therefore caption=text,entry=none,label=none is similar to \caption*{text} in longtable, except for the counter.

While both approaches are working when used on their own (I might have missed some edge cases), I do not get it working in combination.

What am I missing? How can a use the caption package to format the captions of a tabularray table supporting both tables without captions and LOT entries (in the frontmatter) and "normal" tables (in the mainmatter) of my document?

MWE:

\documentclass{scrbook}
\usepackage[english]{babel}

\usepackage[
    font={footnotesize, sf},
    labelfont={bf},
]{caption}

\usepackage{tabularray}
\usepackage{tblr-extras}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{caption}

% remove continuation line at table footer
\DefTblrTemplate{contfoot-text}{default}{}

% define table template with empty captions on first and continued table instances,
% remove continuation line in footer
\DeclareTblrTemplate{caption}{nocaptemplate}{}
\DeclareTblrTemplate{capcont}{nocaptemplate}{}
\DefTblrTemplate{contfoot}{nocaptemplate}{}

% use table template to define new theme
\NewTblrTheme{mytabletheme}{
  \SetTblrTemplate{caption}{nocaptemplate}{}
  \SetTblrTemplate{capcont}{nocaptemplate}{}
  \SetTblrTemplate{caption-lot}{empty}
}

\begin{document}

\frontmatter

\chapter{First Chapter in Frontmatter}

This chapter contains a table without any caption, label or LOT entry:
\begin{itemize}
    \item \texttt{entry = none}
    \item \texttt{label = none}
\end{itemize}

Problem: (Empty) caption and LOT entry are provided, when using \texttt{caption} and \texttt{tblr-extras} packages for formatting. Uncomment corresponding lines in header to see that is it working without the these two packages.

\begin{longtblr}[
    entry = none,
    label = none,
    % apply theme to obtain table without caption on continued table
    theme = mytabletheme,
    ]{
        colspec={
            l
            X[l]
        },
        rowhead = 1, rowfoot = 0,
    }
    \toprule
    column 1 & column 2 \\
    \midrule
    a & b \\
    \pagebreak
    a & b \\
    \bottomrule
\end{longtblr}

\listoftables

\mainmatter

\chapter{First Chapter in Mainmatter}

This chapter contains a table with caption, label and LOT entry.

\begin{longtblr}[
    caption = {The first table with caption},
    entry = {The first table with caption},
    label = {tbl:first_table_with_caption},
    ]{
        colspec={
            l
            X[l]
        },
        rowhead = 1, rowfoot = 0,
    }
    \toprule
    column 1 & column 2 \\
    \midrule
    a & b \\
    \pagebreak
    a & b \\
    \bottomrule
\end{longtblr}

\end{document}

1 Answer 1

1

You are missing templates for firsthead, middlehead and lasthead in your theme.

And, by the way, I cleaned up the code a bit. E.g., \DeclareTblrTemplate -> \DefTblrTemplate for consistency.

\documentclass{scrbook}
\usepackage[english]{babel}

\usepackage[
    font={footnotesize, sf},
    labelfont={bf},
]{caption}

\usepackage{tabularray}
\usepackage{tblr-extras}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{caption}

% remove continuation line at table footer
\DefTblrTemplate{contfoot-text}{default}{}

% define table template with empty captions on first and continued table instances,
% remove continuation line in footer
\DefTblrTemplate{caption}{nocaptemplate}{}
\DefTblrTemplate{capcont}{nocaptemplate}{}
\DefTblrTemplate{contfoot}{nocaptemplate}{}

\DefTblrTemplate{firsthead}{nocaptemplate}{
  \UseTblrTemplate{caption}{nocaptemplate}
}
\DefTblrTemplate{middlehead,lasthead}{nocaptemplate}{
  \UseTblrTemplate{capcont}{nocaptemplate}
}

% use table template to define new theme
\NewTblrTheme{mytabletheme}{
  \SetTblrTemplate{caption}{nocaptemplate}
  \SetTblrTemplate{firsthead,middlehead,lasthead}{nocaptemplate}
  \SetTblrTemplate{capcont}{nocaptemplate}
  \SetTblrTemplate{caption-lot}{empty}
}

\begin{document}

\frontmatter

\chapter{First Chapter in Frontmatter}

This chapter contains a table without any caption, label or LOT entry:
\begin{itemize}
    \item \texttt{entry = none}
    \item \texttt{label = none}
\end{itemize}

Problem: (Empty) caption and LOT entry are provided, when using \texttt{caption} and \texttt{tblr-extras} packages for formatting. Uncomment corresponding lines in header to see that is it working without the these two packages.

\begin{longtblr}[
    entry = none,
    label = none,
    % apply theme to obtain table without caption on continued table
    theme = mytabletheme,
    ]{
        colspec={
            l
            X[l]
        },
        rowhead = 1, rowfoot = 0,
    }
    \toprule
    column 1 & column 2 \\
    \midrule
    a & b \\
    \pagebreak
    a & b \\
    \bottomrule
\end{longtblr}

\listoftables

\mainmatter

\chapter{First Chapter in Mainmatter}

This chapter contains a table with caption, label and LOT entry.

\begin{longtblr}[
    caption = {The first table with caption},
    entry = {The first table with caption},
    label = {tbl:first_table_with_caption},
    ]{
        colspec={
            l
            X[l]
        },
        rowhead = 1, rowfoot = 0,
    }
    \toprule
    column 1 & column 2 \\
    \midrule
    a & b \\
    \pagebreak
    a & b \\
    \bottomrule
\end{longtblr}

\end{document}

enter image description here

enter image description here

enter image description here

You must log in to answer this question.

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