3

I am using longtable with p-column (for the last column which contains long texts). I am also using setspace, as I want to increase the spacing in the main text. Even though setspace does not alter the spacing in the table environment, however, this is not the case with longtable. I found a suggestion to use \begingroup \arraystretch{0.5} \endgroup in order to bypass the spacing in the longtable introduced by setstretch. However, this does not work as expected when using p-columns. It removes the space between the rows of the table, but NOT the space between the rows created by the p-column setting. Is there any workaround?

Any other hints to make this table more presentable (e.g. how to remove the space between the 2 line at the bottom of the table), are welcome.

\documentclass[a4paper,10pt]{article} 
\usepackage{booktabs} 
\usepackage{pdflscape} 
\usepackage{caption} 
\captionsetup[table]{skip=3pt}
\usepackage{longtable} 
\usepackage{setspace}

\begin{document} 
\setstretch{1.45}

\begin{center}
\begingroup
\renewcommand\arraystretch{0.5}

{\small\tabcolsep=1pt
\begin{longtable}{ccccp{5cm}}

\caption{List of Indicators}\\ 
\toprule\midrule

Category & Dataset & Ticker & Num & Description \\

\midrule \endfirsthead
\midrule \endhead 
\midrule \endfoot
\bottomrule \endlastfoot

Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\

\bottomrule
\label{table:vl}
\end{longtable}
}

\endgroup
\end{center}
\end{document}

enter image description here

4
  • 2
    Welcome to TeX.SE. I'd begin by replacing \renewcommand\arraystretch{0.5} with \setstretch{1.0}. Also, don't encase a longtable environment in a centerenvironment.
    – Mico
    Commented Sep 18, 2021 at 0:28
  • 1
    @Mico Thank you! This solves the issue. Why you wouldn't recommend encasing it inside center?
    – CKara
    Commented Sep 18, 2021 at 17:05
  • 2
    There's an excellent reason for not encasing a longtable environment in a center environment: The contents of longtable environments are centered horizontally automatically. Avoiding pointless code redundancy is always good, isn't it? :-)
    – Mico
    Commented Sep 18, 2021 at 17:22
  • 1
    @Mico Indeed, I cannot think of a better reason. XD Thanks for your help!
    – CKara
    Commented Sep 18, 2021 at 18:03

1 Answer 1

3

I changed things from your MWE and may have carried bad practices along with my answer. Therefore, I suggest that you don't learn from my code, although it might help you solve your problem. Maybe someone can improve by editing my answer.

As Mico suggested \setstretch{1.0} might solve spacing between rows and lines inside the p-column

To control spacing between the two last rules, you can use \specialrule in your original MWE. The \bottomrule works like:

\specialrule{\heavyrulewidth}{\aboverulesep}{\belowbottomsep}

So, you can control the spacing above it by using the following instead:

\specialrule{\heavyrulewidth}{-9pt}{\belowbottomsep}

(Edit: you don't even need \specialrule in your case)

Here is the complete code:

\documentclass[a4paper,10pt]{article} 
\usepackage{booktabs} 
\usepackage{pdflscape} 
\usepackage{caption} 
\captionsetup[table]{skip=3pt}
\usepackage{longtable} 
\usepackage{setspace}

\usepackage{lipsum} % <---- To have dummy text
\usepackage[width=16cm]{geometry}  % <---- So that the table has enough space to fit on the page and you see it centered

\begin{document} 
\setstretch{1.45}
\lipsum[1]  % <---- Dummy text (see that the stretching works here)

\begingroup
\setstretch{1.0}
\small
\tabcolsep=1pt
\begin{longtable}{ccccp{5cm}}

\caption{List of Indicators}\\ 
\toprule\midrule

Category & Dataset & Ticker & Num & Description \\

\midrule \endfirsthead
\midrule \endhead 
\midrule \endfoot
\midrule\bottomrule \endlastfoot

Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\[-2pt]
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons) \\
Non-Household Balance Sheets & x2 & TNWMVgh34JRM3 & 103 & Nonfinancial Corporate Business Sector Net Worth to Disposable Business Income (Percent) \\
Stock Markets & x3 & NIKKEI & 0 & Stock Average \\
Labor & x1 & UNEMPLRATE25o & 7 & Unemployment Level - Job Leavers (Thousands of Persons)
% Moved the \bottomrule up to \endlastfoot declaration
\label{table:vl}
\end{longtable}
\endgroup

\lipsum[1]  % <---- Dummy text (see that the stretching works here too)

\end{document}

page1 page2

Note:

The way you've written the top and bottom double lines is causing the table to start with the following widths:

\heavyrulewidth
\lightrulewidth

and to end with the following ones:

\heavyrulewidth
\heavyrulewidth

You probably want to use \toprule\midrule at the beginning and \midrule\bottomrule at the end.

3
  • Thank you for the detailed code. I know that longtable is not compatible with threeparttable. What would be a good method to add a simple table note at the end?
    – CKara
    Commented Sep 18, 2021 at 17:08
  • 1
    @CKara For this you need to use threeparttablex. It has some differences from threeparttable, but the documentation isn't large and has examples that can help you out.
    – Leone
    Commented Sep 18, 2021 at 17:41
  • Thank you so much for your help!
    – CKara
    Commented Sep 18, 2021 at 18:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .