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)?

7
  • 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, 2020 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, 2020 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, 2020 at 22:33
  • You can also use \endhead, \endfoot and \endlastfoot. No problem with that.
    – Bernard
    Apr 29, 2020 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, 2020 at 0:12

1 Answer 1

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

2
  • @Ashitaka, any news?
    – Zarko
    Jun 24, 2021 at 9: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 at 13:48

You must log in to answer this question.

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