2

I am writing a thesis, using a customized document class that I haven't created, but seems to function similarly to article. I have been using longtable for my tables, but am struggling to make the captions single spaced without affecting the spacing of the table contents. I am using the longtable and setspacing packages, and have used \renewcommand{\arraystretch}{0.7} to make the text within the table 0.7 spaced.

I would now like to make the captions single spaced, but am not sure how to separate the command for the caption and for the table contents.

longtable caption formatting had a similar question and \AtBeginEnvironment{longtable}{\linespread{1}\selectfont} was recommended, however that changes the spacing for the whole table, not just the caption. I have tried \captionsetup[longtable]{\linespread{1}\selectfont} however this seems to crash LaTeX.

I feel as though this should be quite simple, and that something along the lines of \AtBeginEnvironment{longtable}{\singlespacing} should be all it takes, though that produces errors (I assume because I already have the \arraystretch command in there). If someone can point me in the right direction it would be greatly appreciated!

1

LT captions are set by

\def\LT@makecaption#1#2#3{%
  \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
    \sbox\@tempboxa{#1{#2: }#3}%
    \ifdim\wd\@tempboxa>\hsize
      #1{#2: }#3%
    \else
      \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
    \fi
    \endgraf\vskip\baselineskip}%
  \hss}}}

so you could use

\makeatletter
\def\LT@makecaption#1#2#3{%
  \LT@mcol\LT@cols c{\hbox to\z@{\hss\parbox[t]\LTcapwidth{%
    \sbox\@tempboxa{#1{#2: }#3}%
    \ifdim\wd\@tempboxa>\hsize
  \singlespacing
      #1{#2: }#3%
    \else
      \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
    \fi
    \endgraf\vskip\baselineskip}%
  \hss}}}
  \makeatother

sorry about the user interface (it's possible that the caption package adds a hook to make this look a bit more natural)

  • Thanks for your response @David! Unfortunately adding it doesn't seem to change anything. It doesn't seem to be that the array stretch is overruling it, as removing that still results in a double spaced caption. I'm afraid I'm at a loss with this one! – Rea Apr 24 '18 at 3:34
  • @Rea well perhaps you added it at the wrong place or perhaps you are loading a package that has changed the option handling or any other reason... If the question had had a small but complete test document showing the problem, this answer would have tested the above code and show the changed output. It's not too late for you to edit the question and have such a file. – David Carlisle Apr 24 '18 at 6:49

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.