[Tex/LaTex] Longtable: wrapped text and justification of columns

longtable

I'm setting a manual line break in a longtable with endfloat. I have created a landscape environment called lgtable and registered it with endfloat so that when the table is sent to the end of the document, it will be landscaped.

When I used a standard table, I surrounded the table with a resizebox and set it equal to \resizebox{1.00\linewidth}{!}{} which ensured that both the wrapped lipsum text at the top of the table went all the way out to the margins, but also that the table itself expanded all the column nicely to fit the page.

However, when I use longtable, I believe I can't surround a longtable with a box, so am stuck about how to incorporate the wrapped text and justified table.

If I omit the wrapped text, the table does justify itself properly, but doesn't extend to the edge of the page. If I include the wrapped text, the columns are not equally spaced out and the wrapped text does not strictly go out to the margins of the page either.

What can I do to ensure the following: the table itself expands to fit the page, the wrapped text expands to fit the page and the columns are spaced out evenly?

\documentclass[11pt]{article}
\usepackage[nolists]{endfloat}
\usepackage{comment}
\usepackage[margin=2.5cm]{geometry}
\usepackage{natbib,amssymb}
\setlength{\bibsep}{0pt plus 0.3ex}

\usepackage[affil-it]{authblk}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx} 
\usepackage{lipsum}
\usepackage[FIGBOTCAP]{subfigure}
\usepackage{float}  
\usepackage{catchfile,tikz}
\usepackage{filecontents}
\usepackage{silence}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{shapes,trees}
\usepackage{pdflscape }
\usepackage{eurosym}
%\usepackage[T1]{fontenc}
\usepackage{mathtools}         
\usepackage{graphicx}

\usepackage{setspace}
\usepackage{lipsum}


\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}%Need for STATA tables

\newenvironment{lgtable}
{\begin{landscape}\begin{longtable}}
{\end{longtable}\end{landscape}}
% make it known to endfloat
\DeclareDelayedFloatFlavor{lgtable}{table}


\begin{document}


\begin{lgtable}{@{\extracolsep{\fill}}l*{8}{c}}
\caption{Regression Estimation: Blank, S(1)} 
\label{table:first}\\
\multicolumn{9}{l}{
\begin{minipage}{1.34\textwidth}
\footnotesize
\lipsum[3-4]\\
\end{minipage}} \\
\toprule
\multicolumn{9}{c}{Some text}\\
\midrule
&Blank& \multicolumn{3}{c}{Some title}&\multicolumn{3}{c}{Some title}& Pooled\\
\midrule
&\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         &\multicolumn{1}{c}{(5)}         &\multicolumn{1}{c}{(6)}         &\multicolumn{1}{c}{(7)}         &\multicolumn{1}{c}{(8)}         \\
&      Blank         &Blank, abcs         &Blank, abcs         &Blank, abcs         & Blank, Abc         & Blank, Abc         & Blank, Abc         &Blank, Pooled         \\
\midrule
S(1)                &       0.900\sym{***}&       0.887\sym{***}&       0.876\sym{***}&       0.239\sym{***}&       0.988\sym{***}&       0.952\sym{***}&       0.330         &       0.258\sym{***}\\
\bottomrule
\newpage
\multicolumn{9}{c}{Table \ref{table:first}: (continued)}\\
\toprule
\multicolumn{9}{c}{Panel B: Seom text}\\
\midrule
&Blank& \multicolumn{3}{c}{Some title}&\multicolumn{3}{c}{Some title}& Pooled\\
\midrule
&\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         &\multicolumn{1}{c}{(5)}         &\multicolumn{1}{c}{(6)}         &\multicolumn{1}{c}{(7)}         &\multicolumn{1}{c}{(8)}         \\
&      Blank         &Blank, abcs         &Blank, abcs         &Blank, abcs         & Blank, Abc         & Blank, Abc         & Blank, Abc         &Blank, Pooled         \\
\midrule
S(1)                &       0.900\sym{***}&       0.887\sym{***}&       0.876\sym{***}&       0.239\sym{***}&       0.988\sym{***}&       0.952\sym{***}&       0.330         &       0.258\sym{***}\\
\bottomrule
\end{lgtable}




\end{document}

Best Answer

This isn't quite what you asked for, but it may do in a pinch. The problem in odd-sized column width seems to arise when a multicolumn extends past the natural width of the table. So I placed your lipsum in a \parbox called \tmp, and then placed it in a 9-column multicolumn with makebox[0pt]{\tmp} (a zero-width box), so that the width of \tmp would not screw up the natural spacing of the table.

This solution has two drawbacks:

1) The table does not extend to the margins, but assumes its natural width, which was not what you asked for; and

2) A tweak is required to the width of the \parbox name d\tmp to make it conform to the natural width of the table. Here, I subtracted 4ex from the full width, which is given by \linewidth.

\documentclass[11pt]{article}
\usepackage[nolists]{endfloat}
\usepackage{comment}
\usepackage[margin=2.5cm]{geometry}
\usepackage{natbib,amssymb}
\setlength{\bibsep}{0pt plus 0.3ex}

\usepackage[affil-it]{authblk}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx} 
\usepackage{lipsum}
\usepackage[FIGBOTCAP]{subfigure}
\usepackage{float}  
\usepackage{catchfile,tikz}
\usepackage{filecontents}
\usepackage{silence}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{shapes,trees}
\usepackage{pdflscape }
\usepackage{eurosym}
%\usepackage[T1]{fontenc}
\usepackage{mathtools}         
\usepackage{graphicx}

\usepackage{setspace}
\usepackage{lipsum}


\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}%Need for STATA tables

\newenvironment{lgtable}
{\begin{landscape}\begin{longtable}}
{\end{longtable}\end{landscape}}
% make it known to endfloat
\DeclareDelayedFloatFlavor{lgtable}{table}


\begin{document}

\def\tmp{\parbox{\linewidth-4ex}{\footnotesize\lipsum[3-4]\vspace{1ex}}}
\begin{lgtable}{@{\extracolsep{\fill}}l*{8}{c}}
\caption{Regression Estimation: Blank, S(1)} 
\label{table:first}\\
\multicolumn{9}{c}{\makebox[0pt]{\tmp}}%
\\
\toprule
\multicolumn{9}{c}{Some text}\\
\midrule
&Blank& \multicolumn{3}{c}{Some title}&\multicolumn{3}{c}{Some title}& Pooled\\
\midrule
&\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         &\multicolumn{1}{c}{(5)}         &\multicolumn{1}{c}{(6)}         &\multicolumn{1}{c}{(7)}         &\multicolumn{1}{c}{(8)}         \\
&      Blank         &Blank, abcs         &Blank, abcs         &Blank, abcs         & Blank, Abc         & Blank, Abc         & Blank, Abc         &Blank, Pooled         \\
\midrule
S(1)                &       0.900\sym{***}&       0.887\sym{***}&       0.876\sym{***}&       0.239\sym{***}&       0.988\sym{***}&       0.952\sym{***}&       0.330         &       0.258\sym{***}\\
\bottomrule
\newpage
\multicolumn{9}{c}{Table \ref{table:first}: (continued)}\\
\toprule
\multicolumn{9}{c}{Panel B: Seom text}\\
\midrule
&Blank& \multicolumn{3}{c}{Some title}&\multicolumn{3}{c}{Some title}& Pooled\\
\midrule
&\multicolumn{1}{c}{(1)}         &\multicolumn{1}{c}{(2)}         &\multicolumn{1}{c}{(3)}         &\multicolumn{1}{c}{(4)}         &\multicolumn{1}{c}{(5)}         &\multicolumn{1}{c}{(6)}         &\multicolumn{1}{c}{(7)}         &\multicolumn{1}{c}{(8)}         \\
&      Blank         &Blank, abcs         &Blank, abcs         &Blank, abcs         & Blank, Abc         & Blank, Abc         & Blank, Abc         &Blank, Pooled         \\
\midrule
S(1)                &       0.900\sym{***}&       0.887\sym{***}&       0.876\sym{***}&       0.239\sym{***}&       0.988\sym{***}&       0.952\sym{***}&       0.330         &       0.258\sym{***}\\
\bottomrule
\end{lgtable}

\end{document}

enter image description here

p.s. Any attempts to extend the natural width of the table ended up adding space only to the last column, which caused me to abandon those attempts.