0

I am using xltabular in order to use tabularx with multi-page tables. I looked at the various options and this one seemed to be the most recent and the one I could get to work.

However, I cannot get custom captions to work with it. Here's a MWE. This compiles, but as soon as I uncomment the \captionsetup command, it no longer compiles. Anyone know a fix for this?

I have tried:

  1. Putting [longtable] as the type in \captionsetup (since in theory xltabular does load longtable).

  2. Moving the \label to the bottom but that makes xltabular upset because for some reason xltabular ONLY works with the label inside the caption brackets.

  3. Tried loading tabularx before and after xltabular (probably unnecessary, and didn't help). In fact, I rearranged the order of all the packages a few times... even doing caption and the options first doesn't work.

Anyone know a fix for this? I have a lot of captions and would rather be able to change it ONCE in the preamble rather than have to change every single caption....

\documentclass[11pt]{article}

\usepackage{xltabular}
\usepackage{caption}
\DeclareCaptionLabelSeparator*{mysep}{:\\}
% \captionsetup {  font            ={small,sc,onehalfspacing},
%                   labelfont       ={bf,sc},
%                   labelsep        =newline,
%                   tableposition   =top,
%                   skip            =5pt}

\begin{document}
% Table
%
\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}%


\begin{xltabular}{\textwidth}{ L{0.1} L{0.15} L{2.8}  L{0.95} }
    \caption{Blah blah blah. \label{tab:blah}}\\
    \hline\hline \multicolumn{2}{c}{Ref}&Focus&Approach\\\hline
    \endfirsthead
    \multicolumn{4}{l}{\dots Continued}\\
    \hline\hline \multicolumn{2}{c}{Ref}&Focus&Approach\\\hline
    \endhead
    \multicolumn{4}{l}{\dots Continued}\\
    \endfoot
    \endlastfoot
    B & Blah         & Words Words Words    & More Words    \\
    B & Blah         & Words Words Words    & More words    \\
    \hline\hline
\end{xltabular}

\end{document}

Edit to ask two follow ups:

This MWE also works correctly in my test document, but for some unknown reason makes the first heading typeset in italics...that just mystifies me.

Second: In my actual document the first version of the table typesets the double \hline correctly. But in THIS version of the table (which isn't that different) it typesets the two \hlines on top of each other.

\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}%
\newcolumntype{M}[1]{>{$}#1<{$}}

\begin{xltabular}{\textwidth}{ M{C{0.25}} L{1.75} }
    \caption{Sets used in ($\mathcal{M}$).\label{tab:set} }\\
    \hline\hline
    Symbol   & Description \\ \hline 
    \endfirsthead
    \multicolumn{2}{l}{\dots Continued}\\ 
    \hline\hline
    Symbol   & Description \\ \hline 
    \endhead
    \multicolumn{2}{r}{Continued\dots}
    \endfoot
    \endlastfoot
    \mathcal{A}          & blah, $a$ \\
    \mathcal{D}          & blah, $d$ \\
    \hline\hline
\end{xltabular}

MWE with all of my ridiculous short cuts! Some of my equations get REALLY long if I don't use short cuts. :-( Basically unreadable without them.

\documentclass[11pt]{article}

\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{setspace}
\usepackage{xltabular}
\usepackage{caption}
\DeclareCaptionLabelSeparator*{mysep}{:\\}
\captionsetup {  font            ={small,sc,onehalfspacing},
                  labelfont       ={bf,sc},
                  labelsep        =mysep,
                  tableposition   =top,
                  skip            =5pt}


\begin{document}

\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}%    
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}%
\newcolumntype{M}[1]{>{$}#1<{$}}
\newcommand{\bfsc}  [1] {\textbf{\sc{#1}}}  % Consistent table heading format
\newcommand{\mc}    [1] {\mathcal{#1}}
\newcommand{\cmctr}[3]
    {\rowcolor{#1}\multicolumn{#2}{c}{\sc{#3}} \\ \hline}
\newcommand{\lp}    {\left(}
\newcommand{\rp}    {\right)}
\newcommand{\aij}   {\lp i,j \rp}

\begin{xltabular}{\textwidth}{ M{C{0.25}} L{1.75} }
    \caption{Sets used in ($\mc{M}$). \label{tab:set} }\\
    \hline\hline
    \bfsc{Symbol}   & \bfsc{Description} \\ \hline 
    \endfirsthead
    \multicolumn{2}{l}{\dots Continued}\\ 
    \hline\hline
    \bfsc{Symbol}   & \bfsc{Description} \\ \hline 
    \endhead
    \multicolumn{2}{r}{Continued\dots}
    \endfoot
    \endlastfoot
    \cmctr{gray!30}{2}{Sets}
    \mc{A}          & blah, $\aij$ \\
    \mc{D}          & blah, $d$ \\
    \hline\hline
\end{xltabular}

\end{document}

Which produces:

Results

1
  • 1
    Well the error message is quite clear: ! Package caption Error: Option onehalfspacing requires the setspace package. So add \usepackage{setspace}. Jan 30, 2020 at 22:20

1 Answer 1

3

There is a very simple fix: load setspace when you want to use \onehalfspacing. I took the opportunity to replace the \hlines with the rules from booktabs, which add some vertical padding to the rules, and have variable thicknesses.

\documentclass[11pt]{article}

\usepackage{setspace}
\usepackage{xltabular}
\usepackage{caption, booktabs}
\DeclareCaptionLabelSeparator*{mysep}{:\\}
 \captionsetup { font ={small, sc, onehalfspacing},%
 labelfont ={bf,sc},
 labelsep =mysep, %newline,
 tableposition =top,
 skip =5pt}

\begin{document}
% Table
%
\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}%

\begin{xltabular}{\textwidth}{ L{0.1} L{0.15} L{2.8} L{0.95} }
    \caption{Blah blah blah. And some more text to see if onehalfspacing works in a caption \label{tab:blah}}\\
    \toprule\midrule \multicolumn{2}{c}{Ref}&Focus&Approach\\\midrule
    \endfirsthead
    \multicolumn{4}{l}{\dots Continued}\\
      \toprule\midrule \multicolumn{2}{c}{Ref}&Focus&Approach\\\hline
    \endhead
    \multicolumn{4}{l}{\dots Continued}\\
    \endfoot
    \endlastfoot
    B & Blah & Words Words Words & More Words \\
    B & Blah & Words Words Words & More words \\
    \midrule\midrule
\end{xltabular}

\end{document} 

enter image description here

10
  • Did not catch that because \usepackage{setspace} was actually loaded in the full document. Which reminds me that I didn't even start to come up with this MWE for that issue, it was another one! I made the MWE by stripping out most of the table formatting because in my main document a similar table (with different column definitions) is putting the two \hline commanbds on top of each other (basically making a bold line) instead of spacing them apart. When I use this MWE in my test document, it looks fine. But in the main document, it doubles the lines up:
    – Jennifer
    Jan 30, 2020 at 22:50
  • oops...I will add the other code up there....
    – Jennifer
    Jan 30, 2020 at 22:50
  • Okay, "follow up" questions posted below original post. The \hline typesetting on top of each other was the original reason I started a test case....
    – Jennifer
    Jan 30, 2020 at 22:55
  • And....using toprule and midrule somehow fixes my \hline\hline problem though I have NO IDEA why when \hline \hline works earlier in the document. It's go to be user error (computers only do what you tell them) but for the life of me I cannot figure out what is that different about the second table!
    – Jennifer
    Jan 30, 2020 at 23:02
  • It is hard to help without knowing what the personal commands do, in your edit. Try to post a minimal and compilable code that reproduces your problem.
    – Bernard
    Jan 30, 2020 at 23:06

You must log in to answer this question.

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