5

I'm having some troubles with captions in longtable tables. I'm trying to typset for a thesis (so am using a class that I didn't write) and my school requires double spacing for body text but single spacing for caption text. To the best that I can determine via google, longtable formats its captions with the formatting specified in the class. I'm using some normal tables and some longtable tables, so the caption formatting is different between tables, which looks odd...

I've found an answer to my almost exact question here but when I try to utilize the answer suggested there, I get an error saying that the "caption" package is not recommended for use and unsupported. That answer was published a few years ago so I'm not really sure what has changed since then.

Anyways, any help would be much appreciated! I'm a pretty basic latex user so appreciate any examples that I can cut/paste/fiddle so I can learn. Thanks!

2

1 Answer 1

11

I don't know what document class you are using, but reading your question it surely loads setspace and uses \doublespacing.

A way to avoid loading the caption package to customize the longtable caption spacing is to load the etoolbox package and put the following line in your preamble:

\AtBeginEnvironment{longtable}{\singlespacing}

In this way you will have single spacing inside all your longtables.

Note also the line

\setlength{\LTcapwidth}{\linewidth}

to make the longtable caption span over the whole line

\documentclass{article}
\usepackage{longtable}
\usepackage{setspace}
\usepackage{lipsum} % just for the example

\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{\singlespacing}

\setlength{\LTcapwidth}{\linewidth}

\begin{document}

\doublespacing

\lipsum[1]

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

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

\lipsum[1-2]

\end{document} 

Output:

enter image description here


EDIT

If you get any error, it means that your document class doesn't load setspace.

In this case, replace the line

\AtBeginEnvironment{longtable}{\singlespacing}

with

\AtBeginEnvironment{longtable}{\linespread{1}\selectfont}

and it should be fine.

3
  • Thanks for this! This is great, and it fixes the minimal working example that I had prepared. Unfortunately, when I try to apply it to my project, it throws an error, saying "! Undefined control sequence. \@begin@longtable@hook ->\singlespacing \begin{longtable}"
    – Tim
    Mar 7, 2014 at 9:04
  • 1
    @Tim See the edited answer. Mar 7, 2014 at 11:03
  • YES! This works perfectly :) Thank you so much for your help!
    – Tim
    Mar 7, 2014 at 23:11

You must log in to answer this question.

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