1

I have been trying to add caption and label to a long table (not entirely written below) inside the xltabular environment. After checking Caption on tabular environment, labels with tabular and some other posts, I did this:

\usepackage{xltabular}
\usepackage{caption}
\captionsetup[table]{skip=-10pt}

\captionof{table}{My Table}
\begin{xltabular}{\textwidth}{@{}Y|Y|Y@{}}
    0.0  & 0    & 0      \\
    1.0  & 1000 & 0      \\
    2.0  & 2000 & 0 
\end{xltabular}

which kinda works. However, I keep getting yellow warning messages:

Package caption Warning: \captionsetup{type*=...} or \captionof outside box or environment on input line 161.

Package caption Warning: The option 'hypcap=true' will be ignored for this particular \caption on input line 161.

Also, \captionsetup[table]{skip=-10pt} stops working if I use \captionof{table}{My Table} and I need it because the space between the table and the caption is too large.

How can I solve these problems without using table environment (it makes my table start in a new page)?

  • 2
    Welcome to TeX SX! As for longtable, the \caption command should be inside the xltabular environment. It is not a floating environmen, and it uses the same syntax as longtable.. – Bernard Apr 29 '20 at 22:13
  • I have tried that multiples times and it did not work. However, by being sure it should (due to your comment), I was able to do so by adding \ after the caption. As for the label, I had to put it inside of \caption{}. It was just a matter or rearranging things after all, but I could only do it thanks to you... So, thanks, @Bernard! :) – Ashitaka Apr 29 '20 at 22:26
  • BTW, @Bernard, won't I be able to use \endhead? Since it will repeat also the caption on every page, once it is inside the xltabular environment... – Ashitaka Apr 29 '20 at 22:33
  • You can also use \endhead, \endfoot and \endlastfoot. No problem with that. – Bernard Apr 29 '20 at 23:46
  • Yea, I know it works. However, it also repeats the caption on every page as if was a header, because it is right after begin{xltabular}, interpreted as a row. I wish I could specify which rows should be repeated. – Ashitaka Apr 30 '20 at 00:12
  • It is stated in the caption documentation that captionof does not work for longtable, see page 37 (section 6.8). If you want to setup special options for the longtable environment you can use \captionsetup[longtable]{options}. It should wotk for xltabular, too. Easier if you have more than one xltabular. – Sveinung Apr 30 '20 at 08:37

1 Answers1

2

Generic model for the use of the xltabular is the same as at longtable:

\documentclass{article}
\usepackage[hmargin=2in, vmargin=0.5in]{geometry}
\usepackage{xltabular}

\usepackage{lipsum}

\begin{document} \listoftables

\section{Test} \lipsum[1-5] \begin{xltabular}{\textwidth}{@{} X|X|X @{}} \caption{My Table} % <--- \label{tab:mytab} \ \hline A & B & C \ \hline \endfirsthead \caption[]{My Table (cont)} \ % <--- \hline A & B & C \ \hline \endhead \hline \multicolumn{3}{r}{\footnotesize\textit{Continue on the next page}} \endfoot \hline \endlastfoot % table body 0.0 & 0 & 0 \ 1.0 & 1000 & 0 \ 2.0 & 2000 & 0 \ 3.0 & 3000 & 0 \ 4.0 & 4000 & 0 \ 5.0 & 5000 & 0 \ 6.0 & 6000 & 0 \ 7.0 & 7000 & 0 \ \end{xltabular} \lipsum[6] \end{document}

enter image description here

Zarko
  • 296,517
  • @Ashitaka, any news? – Zarko Jun 24 '21 at 09:50
  • sorry for this late reply. I haven't checked this topic since my last message, which was prior to your answer. The solution given by Bernard on the comments solved my problem and it seems the only issue was the missing \. Thank you for a complete answer! – Ashitaka Jul 18 '23 at 13:48