2
  • I am looking for a way to have a different caption text for continued captions.
  • I assume that is related to middlehead and or lasthead but I did not understand how to use it.

\documentclass{article}
% "margin = 54mm" is used to control the page break for the MWE.
\usepackage[a4paper, margin = 54mm, landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{longtblr}[ caption = {First Caption}, % mid-caption = {Other Captions}, % <-- Pseudo Code :) % last-caption = {Other Captions}, % <-- Pseudo Code :) entry = {LoT Caption}, label = {tab:label}; ]{ colspec = {t{0.20\linewidth}t{0.20\linewidth}t{0.20\linewidth}}, rowhead = 1, row{1} = {font=\bfseries}, } \toprule A & B & C \ \toprule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\ \bottomrule \end{longtblr}

\end{document}

enter image description here

enter image description here

enter image description here

2 Answers2

4

I can not understand why you want to use different captions in different pages of a long table. It looks a little weird to me. But anyway it is doable: just past two captions to the caption key and retrieve them later with some helper commands.

\documentclass{article}
\usepackage[a6paper,top=35mm,bottom=35mm]{geometry}

\usepackage{tabularray} \UseTblrLibrary{booktabs}

\ExplSyntaxOn \NewDocumentCommand\FirstOfTwo{m}{ \exp_last_unbraced:Ne \use_i:nn { #1 } } \NewDocumentCommand\SecondOfTwo{m}{ \exp_last_unbraced:Ne \use_ii:nn { #1 } } \ExplSyntaxOff

\DefTblrTemplate{caption-text}{first}{\FirstOfTwo{\InsertTblrText{caption}}} \DefTblrTemplate{caption-text}{second}{\SecondOfTwo{\InsertTblrText{caption}}}

\DefTblrTemplate{firsthead}{default}{ \centering \UseTblrTemplate{caption-tag}{default} \UseTblrTemplate{caption-sep}{default} \UseTblrTemplate{caption-text}{first} \par } \DefTblrTemplate{middlehead,lasthead}{default}{ \centering \UseTblrTemplate{caption-tag}{default} \UseTblrTemplate{caption-sep}{default} \UseTblrTemplate{caption-text}{second} \par }

\begin{document}

\begin{longtblr}[ caption = {First Caption}{Second Caption}, entry = {LoT Caption}, label = {tab:label}; ]{ colspec = {t{0.2\linewidth}t{0.2\linewidth}t{0.2\linewidth}}, rowhead = 1, row{1} = {font=\bfseries}, } \toprule A & B & C \ \toprule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\\midrule a & b & c\ \bottomrule \end{longtblr}

\end{document}

enter image description here

L.J.R.
  • 10,932
1

A naive approach would be to define a command to hardcode the text for the middlehead and lasthead. With the command \SetMidLastCaption, you can place any text you like in the "continued captions".

Obviously, it would be much better to define a new key, e.g. mid-caption as you suggested. However, I am not that familiar with expl3, maybe someone else can help.

Found a solution, see edit below.

\documentclass{article}
% "margin = 54mm" is used to control the page break for the MWE.
\usepackage[a4paper, margin = 54mm, landscape]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\ExplSyntaxOn \NewDocumentCommand { \SetMidLastCaption }{ m }{ \DefTblrTemplate{ middlehead, lasthead }{ default } { \centering #1 \par } } \ExplSyntaxOff

% Use the following command to reset the captions to normal behaviour %\SetTblrTemplate{middlehead,lasthead}{normal}

\begin{document}

\SetMidLastCaption{Other Captions}

\begin{longtblr}[
    caption = {First Caption},
    % mid-caption = {Other Captions}, % &lt;-- Pseudo Code :)
    entry = {LoT Caption},
    label = {tab:label};
    ]{
        colspec = {t{0.20\linewidth}t{0.20\linewidth}t{0.20\linewidth}},
        rowhead = 1,
        row{1} = {font=\bfseries},
    }
    \toprule
    A &amp; B &amp; C \\
    \toprule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\\midrule
    a &amp; b &amp; c\\
    \bottomrule
\end{longtblr}

\end{document}

first caption second caption

Edit: Defintion of new key midlast-caption

The following code defines the key midlast-caption as an outer key (used in the optional argument) for tblr. The assignment should be local, meaning if you do not provide the key the captions should use the normal template. If you use midlast-caption = {Other Captions} in the optional argument, the result will be the same as in my first example.

\ExplSyntaxOn
\clist_gput_left:Nn \g__tblr_table_known_keys_clist { midlast-caption }
\keys_define:nn { tblr-outer } { midlast-caption .code:n = \__tblr_set_midlast_caption:n { #1 } }
\cs_new_protected:Npn \__tblr_set_midlast_caption:n #1 {
    \DefTblrTemplate{ middlehead, lasthead }{ default }
    {
        \centering
        #1
        \par
    }
}
\ExplSyntaxOff

Disclaimer I am a complete novice to expl3. Therefore this code might be very bad, use it with caution. I am thankfull for everyone who improves this code.

marv
  • 2,099
  • 1
  • 7
  • 26