0

This question seems to be the same, but I didn't find the answer there.

I have problem with using xltabular and captionsetup in one document.

In this MWE everything works perfect until I use 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}

I tried to put \usepackage{xltabular} in every place in preamble, but it doesn't work.

4
  • What does not work, precisely?
    – Bernard
    Commented Apr 21, 2020 at 11:32
  • @Bernard If I uncomment \usepackage{xltabular} I wiil get an error: Undefined control sequence. \continuetablecaption Commented Apr 21, 2020 at 11:34
  • @Bernard try it out. It is quite obvious what doesn't work. Commented Apr 21, 2020 at 11:35
  • I don't get it, it compiles just fine for me either way. (Edit: Loading xtabular after caption seems to produce the error, but the MWE is fine)
    – steve
    Commented Apr 21, 2020 at 11:56

2 Answers 2

1

You may consider to use tabularray package. Styles of your table captions can be relative simple defined by TblrTemplates:

\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}

which produce:

enter image description here

You may consider default settings for longtblr. I. this case the preambles of document and table are

\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

which produce more usual tale captions at each table parts:

enter image description here

Note: use of xltabular package assume that at least one table's column is of X type. Unfortunately, your MWE doesn't reflect this, so it is unknow, how columns should be formatted. For example, you may write column specification as colspec = {X[l] X[c] X[c]} and get the following result:

enter image description here

0

in order to give you an idea how to easily work with xltabular, I set up the following MWE with the data given in your post.

You do not need a special caption setup for the "running title", i.e. which text appears on the next page. Instead use the area between \endfirsthead and \endhead for that. In my example this is the table ID and the text "continued from previous page".

What I also saw in your code, is that you did not import booktabs. In fact, this is a hard dependency which needs to be imported explicitly.

\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}

You must log in to answer this question.

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