0

I use the set spacing package, to avoid that tables are condensed I also use the etoolbox package to define the tabular environment. However, in one specific table the 1.5 spacing is too much and I would like to reduce it. I tried groups and array stretch but cannot really figure out how to overwrite the spacing for a single table? Any suggestion is appreciated.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\usepackage{etoolbox}

\AtBeginEnvironment{tabular}{\onehalfspacing}

\begin{document}

\section{Introduction}

\begin{table}[h] \begin{tabular}{c|c} aa & bb \ cc & dd \end{tabular} \end{table}

\end{document}

2 Answers2

1

I wouldn't use setspace for that. It's more convenient to redefine the value of \arraystretch, or if you prefer to have cells that look more vertically centred, load the cellspace packge which defines minimal vertical spcinds at the top and bottom of cells in columns with specifier prefixed with the letter S (or C if you also load siunitx, or any letter you please with the column= option).

Demo, in added horizontal lines to help better visualise:

\documentclass{article}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{2pt}
\setlength{\cellspacebottomlimit}{2pt}
\usepackage{setspace}

\begin{document}

\section{Introduction}

\begin{table}[h] {\onehalfspacing \begin{tabular}{c|c} \hline aa & bb \ \hline cc & dd \ \hline \end{tabular}} \qquad { \renewcommand{\arraystretch}{1.1} \begin{tabular}{c|c} \hline aa & bb \ \hline cc & dd \ \hline \end{tabular}} \qquad \begin{tabular}{Sc|Sc} \hline aa & bb \ \hline cc & dd \ \hline \end{tabular} \end{table}

\end{document}

enter image description here

Bernard
  • 271,350
0

With a current latex you could add \singlespacing for the next use of the hook:

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

\AtBeginEnvironment{tabular}{\onehalfspacing}

\begin{document}

\section{Introduction}

\begin{table} \begin{tabular}{c|c} aa & bb \ cc & dd \end{tabular} \end{table}

\begin{table} \AddToHookNext{env/tabular/begin}{\singlespacing} \begin{tabular}{c|c} aa & bb \ cc & dd \end{tabular} \end{table}

\begin{table} \begin{tabular}{c|c} aa & bb \ cc & dd \end{tabular} \end{table}

\end{document}

Side remark: don't use [h] everywhere. If you are unlucky your tables don't fit and then they will pill up at the end of the document. See How to influence the position of float environments like figure and table in LaTeX?

Ulrike Fischer
  • 327,261