[Tex/LaTex] How to doublespace a table using setspace

line-spacingsetspacetables

I have used setspace with \spacing{1.9} to meet publisher specifications of "3 lines per inch or 12 lines per 10 cm", but it does not affect tables, although the publisher has requested that the spacing be applied to tables.

How can I apply this spacing to tables?

Here is an example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{setspace}
\begin{document}
\begin{spacing}{1.9}
\lipsum[1]
\begin{table}[ht]
\begin{tabular}{rlll}
  \hline
 & col1 & col2 & col3 \\ 
  \hline
  50 & 19 & 7 & 26 \\ 
  100 & 10 & 20 & 29 \\ 
  150 & 1 & 7 & 2 \\ 
  200 & 0 & 0 & 10 \\ 
\hline
\end{tabular}
\end{table}
\end{spacing}
\end{document}

enter image description here

Best Answer

The setspace package restores the normal \baselinestretch inside floats (and footnotes); you can override this decision by redefining \@xfloat:

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{lipsum}

\newcommand\Factor{1.9}

\makeatletter
\def\@xfloat#1[#2]{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
       \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
       \@tfor \@tempa :=#2\do
                        {\if\@tempa h\advance\@tempcnta \@ne\fi
                         \if\@tempa t\advance\@tempcnta \tw@\fi
                         \if\@tempa b\advance\@tempcnta 4\relax\fi
                         \if\@tempa p\advance\@tempcnta 8\relax\fi
         }\global\count\@currbox\@tempcnta}\@fltovf\fi
    \global\setbox\@currbox\vbox\bgroup
    \def\baselinestretch{\Factor}\@normalsize
    \boxmaxdepth\z@
    \hsize\columnwidth \@parboxrestore}
\makeatother

\begin{document}
\begin{spacing}{\Factor}
\lipsum[1]
\begin{table}[ht]
\begin{tabular}{rlll}
  \hline
 & col1 & col2 & col3 \\ 
  \hline
  50 & 19 & 7 & 26 \\ 
  100 & 10 & 20 & 29 \\ 
  150 & 1 & 7 & 2 \\ 
  200 & 0 & 0 & 10 \\ 
\hline
\end{tabular}
\end{table}
\end{spacing}
\end{document}

enter image description here

A shorter (and safer) possibility is to use the etoolbox package and its \AtBeginEnvironment command to add \doublespacing to the tabular environment:

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{etoolbox}
\usepackage{lipsum}

\AtBeginEnvironment{tabular}{\doublespacing}

\begin{document}
\begin{spacing}{1.9}
\lipsum[1]
\begin{table}[ht]
\begin{tabular}{rlll}
  \hline
 & col1 & col2 & col3 \\ 
  \hline
  50 & 19 & 7 & 26 \\ 
  100 & 10 & 20 & 29 \\ 
  150 & 1 & 7 & 2 \\ 
  200 & 0 & 0 & 10 \\ 
\hline
\end{tabular}
\end{table}
\end{spacing}
\end{document}
Related Question