2

I am having a nightmare trying to solve this problem. It seems standard captions for figures and tables using memoir class are single spaced, but for tables created using longtable package they are double spaced. I can't make these single spaced using caption + setspace as memoir class doesn't load setspace, using its own code for baseline spacing and scaling (as I understand it). The most promising post I found was this one: Longtable Caption Spacing

I think it is suggesting to change the longtable.sty file in the latex distribution - adding \singlespacing??? If I'm correct, I have now done this but nothing is changing and the captions remain double spaced.

Any suggestions would be warmly welcome - been at this for a good couple of days.

Thanks.

EDIT: Here is a MWE

\documentclass[12pt,oneside]{memoir}

\usepackage{longtable}
\usepackage{lipsum}

\begin{document}


\OnehalfSpacing

\lipsum[1]

    \begin{table}[h]
        \centering
        \caption{Table very very very very very very very very very very very very very long caption}
        \begin{tabular}{llll}
            1 & 1 & 1 & 1\\
            1 & 1 & 1 & 1
        \end{tabular}
        \label{table}
    \end{table}

\setlength{\LTcapwidth}{\linewidth}
    \begin{longtable}{llll}
        \caption{Longtable very very very very very very very very very very very very very long caption} \\
        1 & 1 & 1 & 1\\
        1 & 1 & 1 & 1\\
        \label{longtable}
    \end{longtable}

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{10pt}
    \begin{longtable}[htbp]{lcclcl}

        \caption[Specimen Collection]{Specimen information including species name, institution accession or record number, sex of specimen, host species name, year the specimen was collected, and location it was collected. Sex: F = Female, M = Male, j. = juvenile, t. = transitionary stage.}
        \label{table:museo} \\ \toprule

        \multicolumn{1}{c}{Species}  & \multicolumn{1}{c}{Acc./Record} & \multicolumn{1}{c}{Sex} & \multicolumn{1}{c}{Host}  & \multicolumn{1}{c}{Year Collected} & \multicolumn{1}{c}{Location} \\ \hline
    \end{longtable}


    \lipsum[2]

\end{document} 

You'll see in tables 2 and 3 the caption line spacing is 1.5, whereas, using a normal table, table 1 is single spaced. I've now changed back the longtable.sty file as that solution didn't work anyway.

EDIT: All Packages

\usepackage{lineno}

\usepackage{amsmath,amsthm,amssymb,amsfonts}

\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition} 

\usepackage{microtype}

\usepackage[dvipsnames]{xcolor}


\makeatletter
\newcommand\GIANT{\@setfontsize\Huge{20}{0}}
\makeatother  

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{0pt}{\GIANT}

\usepackage[numbered]{bookmark}

\usepackage{url} 
\PassOptionsToPackage{hyphens,spaces,obeyspaces}{url}\usepackage{hyperref}

\usepackage{textcomp}

\usepackage{color, colortbl} 

\usepackage[final]{pdfpages}

\usepackage{adjustbox}

\usepackage{multirow}

\usepackage{graphicx}

\usepackage{blindtext}

\usepackage{tgheros}
\renewcommand*\familydefault{\sfdefault}

\usepackage[T1]{fontenc}

\usepackage[helvet]{sfmath}

\usepackage[left=3.5cm,right=2cm, bottom=2.5cm, headsep=40pt]{geometry}

\usepackage{siunitx,booktabs,array,calc}

%\usepackage{setspace} doesn't work with memoir???

\usepackage{caption}

\usepackage{longtable}

\usepackage{etoolbox}

\usepackage{lscape}

\usepackage{rotating}

\usepackage{natbib}
\newcommand\cites[1]{\citeauthor{#1}'s\ (\citeyear{#1})} %adds possessive citation \cites{}
\newcommand{\citeay}[1]{\citeauthor{#1}, \citeyear{#1}} % comman in citealt
\bibpunct[, ]{(}{)}{;}{a}{,}{,}

  • I should clarify I want the actual table spacing to be 1.5 - it's only the caption I want to alter – Charles Baillie Oct 20 '19 at 15:57
  • Could you please add a minimal working example (MWE) with your current line spacing settings and as well as an example longtable? – leandriis Oct 20 '19 at 15:59
  • Please do not directly change the .styfile of an existing package. – leandriis Oct 20 '19 at 16:01
  • 1
    \usepackage{etoolbox}\makeatletter\patchcmd\LT@makecaption{\sbox}{\singlespacing\sbox}{}{\GenericError{}{Patching failed}{}{}}\makeatother in the preamble should work (untested though, due to lacking MWE). – Skillmon Oct 20 '19 at 16:41
  • 1
    You need load etoollbox yourself. – Zarko Oct 20 '19 at 19:40
2

Nice hack 1 (or ‘hack-patch 1’)

After some tinkering, I discover a (hopefully) better solution. Instead of manipulating \baselinestretch I suggest using the \fontsize{<fontsize>}{<leading>}-command. It is just to reset the the font size to the caption's fontsize (here 12 pt) and use the second parameter to create the single spacing. LaTeX normally set 20 per cent leading, so the correct command should be \fontsize{12}{13.2}\selectfont}. However, you may compress the caption by using 12 pt or 12.5 pt leading.

Using the \fontsize-command, you do not need to set the optional [Short caption].

In addition, I suggest defining a shorthand, \sspace so you can change leading one place. Maybe this even deserves to be called a patch, or at least a ‘hack-patch’ or ‘patch-hack’, since I use a font command:

enter image description here

\documentclass[12pt,oneside]{memoir}
\newcommand{\sspace}{\fontsize{12}{12}\selectfont} 

\usepackage{longtable}
%\usepackage{caption}
\usepackage{lipsum}

\begin{document}


\OnehalfSpacing

\lipsum[1]

    \begin{table}[h]
        \centering
        \caption{\sspace Table very very very very very very very very very very very very very long caption.}
        \begin{tabular}{llll}
            1 & 1 & 1 & 1\\
            1 & 1 & 1 & 1
        \end{tabular}
        \label{table}
    \end{table}

\setlength{\LTcapwidth}{\linewidth}
    \begin{longtable}{llll}
        \caption{\sspace Longtable very very very very very very very very very very very very very long caption.} \\
        1 & 1 & 1 & 1\\
        1 & 1 & 1 & 1\\
        \label{longtable}
    \end{longtable}

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{10pt}
    \begin{longtable}[htbp]{lcclcl}

        \caption{\sspace Specimen information including species name, institution accession or record number, sex of specimen, host species name, year the specimen was collected, and location it was collected. Sex: F = Female, M = Male, j. = juvenile, t. = transitionary stage.}
        \label{table:museo} \\ \toprule

        \multicolumn{1}{c}{Species}  & \multicolumn{1}{c}{Acc./Record} & \multicolumn{1}{c}{Sex} & \multicolumn{1}{c}{Host}  & \multicolumn{1}{c}{Year Collected} & \multicolumn{1}{c}{Location} \\ \hline
    \end{longtable}


    \lipsum[2]

\end{document} 

Crude hack 1

Here is a crude hack that works, add \renewcommand\baselinestretch{1}\selectfontto the caption. For some reason, you must set the optional short captions [Long caption]:

enter image description here

\documentclass[12pt,oneside]{memoir}

\usepackage{longtable}
\usepackage{lipsum}

\begin{document}


\OnehalfSpacing

\lipsum[1]

    \begin{table}[h]
        \centering
        \caption{Table very very very very very very very very very very very very very long caption}
        \begin{tabular}{llll}
            1 & 1 & 1 & 1\\
            1 & 1 & 1 & 1
        \end{tabular}
        \label{table}
    \end{table}

\setlength{\LTcapwidth}{\linewidth}
    \begin{longtable}{llll}
        \caption[Long Caption]{\renewcommand\baselinestretch{1}\selectfont Longtable very very very very very very very very very very very very very long caption} \\
        1 & 1 & 1 & 1\\
        1 & 1 & 1 & 1\\
        \label{longtable}
    \end{longtable}

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{10pt}
    \begin{longtable}[htbp]{lcclcl}

        \caption[Specimen Collection]{\renewcommand\baselinestretch{1}\selectfont Specimen information including species name, institution accession or record number, sex of specimen, host species name, year the specimen was collected, and location it was collected. Sex: F = Female, M = Male, j. = juvenile, t. = transitionary stage.}
        \label{table:museo} \\ \toprule

        \multicolumn{1}{c}{Species}  & \multicolumn{1}{c}{Acc./Record} & \multicolumn{1}{c}{Sex} & \multicolumn{1}{c}{Host}  & \multicolumn{1}{c}{Year Collected} & \multicolumn{1}{c}{Location} \\ \hline
    \end{longtable}


    \lipsum[2]

\end{document} 
| improve this answer | |
  • Both answers work with my MWE but for some reason @Skillmon 's solution doesn't work in my actual document, hence the using this as the accepted answer. Thanks!!! – Charles Baillie Oct 21 '19 at 19:13
  • @CharlesBaillie if my answer doesn't work in your actual document, can you please provide a list of packages you're using, so I can take a look. I don't think that using this answer is the proper approach and that correctly fixing it is the way to go. – Skillmon Oct 22 '19 at 9:27
  • @Skillmon If a solution works, why is it not a proper approach. It is clean, simple and transparent. If you have hundreds of longtables, I agree that a complicated patch may seem to be better, but the risk is that the patch breaks when you load a new, or updated, package. If you have hundreds of longtables, of cause you define a shortcut to implement my solution, and then you can change the definition of the shortcut at one place. Often, good enough is the best. – Sveinung Oct 22 '19 at 13:34
  • @Sveinung I beg to disagree, there shouldn't be any general formatting macros inside the caption necessary. The LaTeX-way of things would be to change the definition of \LT@makecaption such that it is correct, not to include some macro in every argument of said macro. So while I agree that your answer solves the issue at hand, it doesn't solve it in a proper LaTeX-y approach. – Skillmon Oct 22 '19 at 14:48
  • @Skillmon Well, your patch add a command inside the caption, too, and is a hack, exactly as my solution. The only "proper" LaTeX solution would be that the package authors change the packages. – Sveinung Oct 22 '19 at 16:41
2

The following patches \LT@makecaption at the correct point with the correct information for your MWE. Problem is that the macro is getting redefined and this removes the patch. If we patch \AtBeginDocument this should work, also we don't search for \sbox as the new definition doesn't use \sbox but we use \let as that is the first token inside the \parbox which surrounds the caption:

EDIT: I changed the answer a bit to so that it works whether the caption package is loaded or not. It could still fail if you use other packages which redefine \LT@makecaption.

\documentclass[12pt,oneside]{memoir}

\usepackage{longtable}
\usepackage{lipsum}
\usepackage{etoolbox}
%\usepackage{caption}

\makeatletter
\AtBeginDocument
  {%
    \@ifpackageloaded{caption}
      {%
        \patchcmd\LT@makecaption{\caption@@make}{\SingleSpacing\caption@@make}
      }
      {%
        \patchcmd\LT@makecaption{\let}{\SingleSpacing\let}
      }
      {}{\errmessage{patch failed!}}%
  }
\makeatother

\begin{document}

\OnehalfSpacing

\lipsum[1]

    \begin{table}[h]
        \centering
        \caption{Table very very very very very very very very very very very very very long caption}
        \begin{tabular}{llll}
            1 & 1 & 1 & 1\\
            1 & 1 & 1 & 1
        \end{tabular}
        \label{table}
    \end{table}

\setlength{\LTcapwidth}{\linewidth}
    \begin{longtable}{llll}
        \caption{Longtable very very very very very very very very very very very very very long caption} \\
        1 & 1 & 1 & 1\\
        1 & 1 & 1 & 1\\
        \label{longtable}
    \end{longtable}

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{10pt}
    \begin{longtable}[htbp]{lcclcl}

        \caption[Specimen Collection]{Specimen information including species name, institution accession or record number, sex of specimen, host species name, year the specimen was collected, and location it was collected. Sex: F = Female, M = Male, j. = juvenile, t. = transitionary stage.}
        \label{table:museo} \\ \toprule

        \multicolumn{1}{c}{Species}  & \multicolumn{1}{c}{Acc./Record} & \multicolumn{1}{c}{Sex} & \multicolumn{1}{c}{Host}  & \multicolumn{1}{c}{Year Collected} & \multicolumn{1}{c}{Location} \\ \hline
    \end{longtable}


    \lipsum[2]

\end{document}

enter image description here

| improve this answer | |
  • Thanks for the solutions - I actually understand where the redefinition is occurring now!!!! Also, thanks for the philosophical discussion with @Sveinung. I'll stick with the answer I accepted first, but agree that this one is more elegant (only having to patch once rather than in each caption) at least where other packages don't redefine caption spacing. – Charles Baillie Oct 23 '19 at 13:13
  • @CharlesBaillie It should not be a big issue to change Skillmon's ha.. , sorry, patch so that it put the commands I suggest into the beginning of the caption. – Sveinung Oct 27 '19 at 17:09
  • @Sveinung there is no need for that. The current form of the answer should work in his document. – Skillmon Oct 27 '19 at 18:14
  • @Skillmon Then I misunderstood Charles Baillie's comment. – Sveinung Oct 27 '19 at 18:28
  • @Sveinung he didn't comment that it doesn't work currently (as I understood), but that he fears it'll cease to work if he loads other packages as well, and therefore sticks with your answer. – Skillmon Oct 27 '19 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.