Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
    
Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. –  karlkoeller Mar 7 at 5:16
    
Which class you are using? Can you provide a link to that class file? –  Harish Kumar Mar 7 at 5:41

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
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 at 9:04
1  
@Tim See the edited answer. –  karlkoeller Mar 7 at 11:03
    
YES! This works perfectly :) Thank you so much for your help! –  Tim Mar 7 at 23:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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