如何将 captionsetup 与 xltabular 一起使用?

如何将 captionsetup 与 xltabular 一起使用?

问题似乎相同,但我没有在那里找到答案。

我在一个文档中使用xltabular和时遇到问题。captionsetup

在这个 MWE 中一切都运行正常,直到我使用xltabular

\documentclass{article}
\usepackage{longtable}
%\usepackage{xltabular}
\usepackage{caption}

\newcommand{\continuetablecaption}{%
    \captionsetup{name=\textit{Continue of table},font=it}
    \caption{}
}%


\begin{document}



\begin{longtable}{|c|c|c|}

    \caption{Animal table}\\
    \hline
    animal & weight &  length \\ \hline
    \endfirsthead

    \continuetablecaption\\
    \hline
    animal & weight &  length \\ \hline
    \endhead

elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
\end{longtable}

\end{document}

我尝试将其放入\usepackage{xltabular}序言中的每个位置,但没有效果。

答案1

您可以考虑使用tabularray包。表格标题的样式可以相对简单,由TblrTemplate以下代码定义:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\DefTblrTemplate{capcont}{nc}{% definitions for continue caption style
  \par\centering
    \DefTblrTemplate {conthead-text}{nc}{Continue of table}
    \UseTblrTemplate {conthead-text}{nc}
  \par
}
\NewTblrTheme{scc}{% captions styles
    \SetTblrTemplate{capcont}{nc}%
    \SetTblrStyle{conthead-text}{font=\small}
    \SetTblrStyle{contfoot-text}{font=\footnotesize\itshape}
%
    \SetTblrStyle{caption-text}{font=\small}
    \SetTblrStyle{caption-tag}{font=\small\bfseries}
}

\begin{document}
    \begin{longtblr}[theme = scc,
caption = {Animal table},
  label = {tab:animal}
                    ]{hline{3-Y}, vlines,
                     colspec = {l cc},
                      row{1} = {font=\bfseries},
                     rowhead = 1
                     }
% Headline
    \toprule
animal  & weight &  length   \\
    \midrule
        % table content column by column, row by row
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
%\end{longtblr}
%\end{document}
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
elephant & 5 t & 3 m \\
    \bottomrule
\end{longtblr}
\end{document}

其生产成果为:

在此处输入图片描述

您可以考虑默认设置longtblr。I. 在这种情况下,文档和表格的序言是

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}


\begin{document}
    \begin{longtblr}[
caption = {Animal table},
  label = {tab:animal}
                    ]{hline{3-Y}, vlines,
                     colspec = {l cc},
                      colsep = 9pt,
                      row{1} = {font=\bfseries},
                     rowhead = 1
                     }
% Headline

在每个表格部分都会产生更多常见的故事标题:

在此处输入图片描述

笔记: 包的使用xltabular假设至少一个表的列是X类型。不幸的是,您的 MWE 没有反映这一点,因此不知道应该如何格式化列。例如,您可以将列规范写为colspec = {X[l] X[c] X[c]}并得到以下结果:

在此处输入图片描述

答案2

为了让您了解如何轻松使用xltabular,我使用您帖子中提供的数据设置了以下 MWE。

您不需要为“连续标题”设置特殊的标题,即下一页上显示的文本。而是使用\endfirsthead和之间的区域\endhead。在我的示例中,这是表格 ID 和文本“上一页的续篇”。

我还在您的代码中看到,您没有导入booktabs。事实上,这是一个需要明确导入的硬依赖项。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tabularx}
\usepackage{xltabular}
\usepackage{booktabs} 

\begin{document}
\begin{xltabular}{\linewidth}{|c|c|c|}
    \caption{Animal table} \\ % This line break is needed, otherwise timeout in compilation
    
     % Headline
        \toprule
        animal & weight &  length \\ \hline
        \endfirsthead 
       
        \multicolumn{3}{c}%
        {{\textbf{\tablename} \thetable{} -- continued from previous page}} \\
        \toprule
        animal & weight &  length \\ \hline 
        \endhead
        
        \multicolumn{3}{r}{{\textit{Continued on next page}}}  \\ 
        \endfoot
        
        \bottomrule  % the really end of the table
        \endlastfoot

        % table content column by column, row by row
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline
elephant & 5 t & 3 m \\ \hline

\end{xltabular}
\end{document}

相关内容