I am writing a document class for my thesis, and now I am trying to control the line spacing in the table environment. I use \setstretch{1.5} to set the line spacing for main text. I want to make the line spacing in table (or table-like) environment to be the same (\baselinestretch=1.5). However, it seems like \setstretch only affects tabular or table with [H] option. In table with common floating options, the stretch is reset to 1. The following MWE may of some help:
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\usepackage{geometry}
\geometry{scale=0.75}
\usepackage{lipsum} % only for MWE
\usepackage{float}
\usepackage{booktabs}
\setstretch{1.5} % set the line spacing
\begin{document}
\section{Introduction}
\lipsum[1]
\begin{table}[H] % Here the line spacing is correct.
\centering
\begin{tabular}{cc}
\toprule
test & test \
test & test \
test & test \
test & test \
\bottomrule
\end{tabular}
\caption{Test Table 1}
\label{tab:my_label1}
\end{table}
\begin{table}[ht] % Here is not.
\centering
\begin{tabular}{cc}
\toprule
test & test \
test & test \
test & test \
test & test \
\bottomrule
\end{tabular}
\caption{Test Table 2}
\label{tab:my_label2}
\end{table}
\end{document}
How can I obtain the same line spacing in table as in the document texts?
Besides, I notice that if I put an \setstretch inside the table, the line spacing is correct. But I don't want put this in all of my tables, can it be set globally? (By the way, I tried \AtBeginEnvironment{table}{\setstretch{1.5}} with etoolbox package, but it does not work.)
\begin{table}[ht]
\setstretch{1.5} % After adding this, the line spacing is correct.
\centering
\begin{tabular}{cc}
\toprule
test & test \\
test & test \\
test & test \\
test & test \\
\bottomrule
\end{tabular}
\caption{Test Table 3}
\label{tab:my_label3}
\end{table}
tabularandtable[H]by another 1.5, which makes the line spacing become 2.25 in these environments. – SuikaXhq May 17 '22 at 15:34\renewcommand{\arraystretch}{1.5}in the float, not in the preamble, or (better) for the shake of the document layout , set this in the preamble, and do not use fake floats with [H] at all. – Fran May 18 '22 at 05:48