[Tex/LaTex] Using longtable with multicolumn heading

longtablemulticolumn

I am formatting a table for my dissertation. The graduate school requires that the margins be 1.25 inches on each side and 1 inch from top/bottom of the text. So that table below is too large to fit on one page. I would like to use the longtable feature but am unsure how to do this as (1) I need to repeat the first row on each page and (2) I have a multicolumn table. I would like the table to break after Recycle vs. Store results (i.e. sub-column VI). The lengthy number of packages are requirements for the graduate school template. Please let me know if you have any suggestions!

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}

\usepackage{longtable}
\usepackage{siunitx,booktabs,threeparttable,caption}
% Additional packages here
\usepackage{amsmath}
\usepackage{bigstrut}
\usepackage{url}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{float}
\usepackage{wasysym}
\usepackage{amsmath}
\usepackage{bigstrut}
\usepackage{url}
\usepackage{natbib,epstopdf}
\usepackage{multirow}
\usepackage{pdflscape}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tablefootnote}
\usepackage{bm}
\usepackage{wrapfig}
\usepackage[demo]{graphicx}

\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet5'
\begin{landscape}
\begin{table}[h]\centering
   \caption{MNL Model with Grouped Disposal as DV}
   \footnotesize{
\begin{tabular}{lccccccccccc}
\cmidrule{2-12}          & \multicolumn{3}{c}{\textbf{Recycle vs. Trash }} &       & \multicolumn{3}{c}{\textbf{Recycle vs. Store }} &       & \multicolumn{3}{c}{\textbf{Store vs Trash }} \\
\cmidrule{2-12}          & \multicolumn{1}{c}{I} & \multicolumn{1}{c}{II} & \multicolumn{1}{c}{III} &       & \multicolumn{1}{c}{IV} & \multicolumn{1}{c}{V} & \multicolumn{1}{c}{VI} &       & \multicolumn{1}{c}{VII} & \multicolumn{1}{c}{VIII} & \multicolumn{1}{c}{IX} \\
          & \multicolumn{1}{c}{Coef.} & \multicolumn{1}{c}{Std. Error} & \multicolumn{1}{c}{Odds ratio} &       & \multicolumn{1}{c}{Coef.} & \multicolumn{1}{c}{Std. Error} & \multicolumn{1}{c}{Odds ratio} &       & \multicolumn{1}{c}{Coef.} & \multicolumn{1}{c}{Std. Error} & \multicolumn{1}{c}{Odds ratio} \\
\cmidrule{2-12}    1. EPR: Yes & $0.44^{*}$  & 0.21  & 1.55  &       & 0.06  & 0.18  & 1.06  &       & 0.38  & 0.24  & 1.46 \\
    1. LEGALAWARENESS: Yes & 0.07  & 0.22  & 1.07  &       & -$0.34^{*}$ & 0.16  & 0.71  &       & 0.41  & 0.25  & 1.50 \\
    1. LOCTAWARENESS: Maybe & $1.37^{***}$  & 0.23  & 3.92  &       & 1.17  & 0.19  & 3.92  &       & 0.20  & 0.28  & 1.22 \\
    2. LOCTAWARENESS: Yes & $1.67^{***}$  & 0.26  & 5.30  &       & $1.48^{***}$  & 0.20  & 4.41  &       & 0.18  & 0.30  & 1.20 \\
    2. IMPORTANCE: Not very & -0.08 & 0.66  & 0.95  &       & -0.65 & 0.95  & 0.52  &       & 0.56  & 0.88  & 1.76 \\
    3. IMPORTANCE: Neutral & $1.03^{\hat{}}$  & 0.58  & 2.80  &       & 0.25  & 0.87  & 1.28  &       & 0.78  & 0.82  & 2.18 \\
    4. IMPORTANCE: Somewhat Important & $1.95^{**}$  & 0.57  & 7.06  &       & -0.32 & 0.84  & 0.73  &       & $2.28^{**}$  & 0.80  & 9.74 \\
    5. IMPORTANCE: Very Important & $2.34^{***}$  & 0.57  & 10.41 &       & 0.02  & 0.85  & 10.41 &       & $2.32^{**}$  & 0.81  & 10.17 \\
    1. INFOSOURCE: General & 0.41  & 0.34  & 1.51  &       & $1.19^{***}$  & 0.31  & 3.30  &       & -$0.78^{*}$ & 0.40  & 0.46 \\
    2. INFOSOURCE: Government & $0.76^{*}$  & 0.36  & 2.14  &       & $1.08^{***}$  & 0.30  & 2.94  &       & -0.32 & 0.40  & 0.73 \\
    3. INFOSOURCE: Retailer Manufacturer & 0.55  & 0.39  & 1.74  &       & $0.77^{**}$  & 0.34  & 2.66  &       & -0.42 & 0.46  & 0.65 \\
    4. INFOSOURCE: Non Profit & $0.77^{*}$  & 0.38  & 2.16  &       & $1.09^{***}$  & 0.32  & 2.98  &       & -0.32 & 0.44  & 0.73 \\
    1. PREVENT: Too Expensive & -1.19 & 0.77  & 0.31  &       & -0.60 & 0.47  & 0.55  &       & -0.59 & 0.89  & 0.55 \\
    2. PREVENT: Inconvenient Location & -$1.73^{*}$ & 0.74  & 0.18  &       & -$1.06^{*}$ & 0.45  & 0.35  &       & -0.67 & 0.86  & 0.51 \\
    3. PREVENT: Unable to Transport & -1.13 & 0.75  & 0.32  &       & -0.22 & 0.47  & 0.81  &       & -0.91 & 0.88  & 0.40 \\
    4. PREVENT: Unaware of Location & -$1.57^{*}$ & 0.73  & 0.21  &       & -$0.87^{*}$ & 0.46  & 0.42  &       & -0.70 & 0.86  & 0.50 \\
    1. RURAL: Yes & -0.23 & 0.19  & 0.78  &       & -$0.37^{**}$ & 0.15  & 0.69  &       & 0.14  & 0.22  & 1.16 \\
    2. AGE: 36-45 & 0.35  & 0.29  & 1.43  &       & 0.05  & 0.20  & 2.95  &       & 0.31  & 0.32  & 0.58 \\
    3. AGE: 46-55 & 0.00  & 0.25  & 0.98  &       & $0.94^{***}$  & 0.23  & 2.55  &       & -$0.94^{**}$ & 0.31  & 0.39 \\
    4. AGE: 56-65 & 0.44  & 0.28  & 1.49  &       & $1.09^{***}$  & 0.24  & 2.95  &       & -$0.65^{*}$ & 0.33  & 0.52 \\
    5. AGE: 66+ & $0.60^{\hat{}}$  & 0.34  & 1.82  &       & $1.14^{***}$  & 0.29  & 3.13  &       & -0.54 & 0.41  & 0.58 \\
    2. DISTANCE: 1-5 miles & $0.61^{**}$  & 0.23  & 1.83  &       & 0.45  & 0.28  & 1.57  &       & -$0.47^{**}$ & 0.41  & 0.62 \\
    3. DISTANCE: 6-10 miles & 0.38  & 0.25  & 1.46  &       & 0.33  & 0.27  & 1.39  &       & 0.25  & 0.40  & 1.29 \\
    4. DISTANCE: 11-20 miles & $0.02^{\hat{}}$  & 0.34  & 1.02  &       & 0.54  & 0.29  & 1.42  &       & -0.19 & 0.42  & 0.83 \\
    \bottomrule
     \midrule
\textit{***p $<$ .001, ** p $<$.01, *p$<$.05, $^\wedge$ p$<$.1} &       &       &       &       &       &       &       &       &        \\
\end{tabular}}
  \label{tab:results}%
\end{table}%
\end{landscape}

Best Answer

  • First step: clean-up your MWE:

enter image description here

MWE (not consider complete provided table, for it is to much work and you can finish it on the same way as it is shown for eight first rows:

\documentclass[english]{article}
\usepackage{booktabs, makecell}
\renewcommand\theadfont{\small\bfseries}
\usepackage{siunitx}
\usepackage{caption}

% Additional packages here
\usepackage{amsmath}
\usepackage{pdflscape}

\begin{document}

\begin{landscape}
\begin{table}
    \centering
    \setlength\tabcolsep{2pt}
   \caption{MNL Model with Grouped Disposal as DV}
\begin{tabular*}{\linewidth}
                {@{\extracolsep{\fill}}
                l 
           *{3}{S[table-format=-1.2, 
                  table-space-text-post={***}] 
                S[table-format=1.2] 
                S[table-format=2.2]}
                }
\cmidrule{2-10}          
    & \multicolumn{3}{c}{\thead{Recycle vs. Trash }} 
    & \multicolumn{3}{c}{\thead{Recycle vs. Store }} 
    & \multicolumn{3}{c}{\thead{Store vs Trash }} \\
\cmidrule(lr){2-4}          
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}
    & {I}       & {II} & {III} & {IV} & {V} & {VI} & {VII} & {VIII} & {IX} \\
    & {Coef.}   
    & {\makecell[b]{Std.\\ Error}} 
    & {\makecell[b]{Odds\\ ratio}} 
    & {Coef.} 
    & {\makecell[b]{Std.\\ Error}}
    & {\makecell[b]{Odds\\ ratio}}
    & {Coef.}   
    & {\makecell[b]{Std.\\ Error}} 
    & {\makecell[b]{Odds\\ ratio}} \\
\midrule   
1. EPR: Yes     
    & 0.44* & 0.21  & 1.55  & 0.06  & 0.18  & 1.06  & 0.38  & 0.24  & 1.46  \\
1. LEGALAWARENESS: Yes 
    & 0.07  & 0.22  & 1.07  & -0.34 & 0.16  & 0.71  & 0.41  & 0.25  & 1.50 \\
1. LOCTAWARENESS: Maybe 
    &  1.37***  & 0.23 & 3.92 & 1.17 & 0.19 & 3.92  & 0.20  & 0.28  & 1.22 \\
2. LOCTAWARENESS: Yes 
    & 1.67***   & 0.26 & 5.30 & 1.48*** & 0.20  & 4.41  & 0.18  & 0.30  & 1.20 \\
2. IMPORTANCE: Not very 
    & -0.08 & 0.66  & 0.95 & -0.65 & 0.95  & 0.52  & 0.56  & 0.88  & 1.76 \\
3. IMPORTANCE: Neutral 
    & 1.03  & 0.58  & 2.80 & 0.25  & 0.87  & 1.28  & 0.78  & 0.82  & 2.18 \\
4. IMPORTANCE: Somewhat Important 
    & 1.95**    & 0.57  & 7.06  & -0.32 & 0.84  & 0.73  & 2.28**   & 0.80  & 9.74 \\
5. IMPORTANCE: Very Important 
    & 2.34  & 0.57  & 10.41 & 0.02  & 0.85  & 10.41 & 2.32{**}  & 0.81  & 10.17 \\
     \midrule[\heavyrulewidth]
\multicolumn{10}{l}{
\textit{***p $<$ .001, ** p $<$.01, *p$<$.05, $^\wedge$ p$<$.1}
                    }
\end{tabular*}
  \label{tab:results}%
\end{table}%
\end{landscape}
\end{document}
  • second step: transform your table to long table. For longtable is not possible to prescribe table width, however experiences from standard table show, that it will fit to available text width with equal settings for \tabcolsep.

\documentclass[english]{article}
\usepackage{booktabs, makecell, longtable}
\renewcommand\theadfont{\small\bfseries}
\usepackage{siunitx}
\usepackage{caption}
% Additional packages here
\usepackage{amsmath}
\usepackage{pdflscape}
%\usepackage[table]{xcolor}

\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet5'
\begin{landscape}

    \setlength\tabcolsep{3pt}
\begin{longtable}{
                l 
           *{3}{S[table-format=-1.2, 
                  table-space-text-post={***}] 
                S[table-format=1.2] 
                S[table-format=2.2]}
                }
    \caption{MNL Model with Grouped Disposal as DV} 
    \label{tab:results}                             \\%
\cmidrule{2-10}          
    & \multicolumn{3}{c}{\thead{Recycle vs. Trash }} 
    & \multicolumn{3}{c}{\thead{Recycle vs. Store }} 
    & \multicolumn{3}{c}{\thead{Store vs Trash }}   \\
\cmidrule(lr){2-4}          
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}
    & {I}       & {II} & {III} & {IV} & {V} & {VI} & {VII} & {VIII} & {IX} \\
    & {Coef.}   
    & {\makecell[b]{Std.\\ Error}} 
    & {\makecell[b]{Odds\\ ratio}} 
    & {Coef.} 
    & {\makecell[b]{Std.\\ Error}}
    & {\makecell[b]{Odds\\ ratio}}
    & {Coef.}   
    & {\makecell[b]{Std.\\ Error}} 
    & {\makecell[b]{Odds\\ ratio}} \\
\midrule 
    \endfirsthead
%%%%
    \caption{MNL Model with Grouped Disposal as DV (Cont.)} \\
\cmidrule{2-10}
    & \multicolumn{3}{c}{\thead{Recycle vs. Trash }}
    & \multicolumn{3}{c}{\thead{Recycle vs. Store }}
    & \multicolumn{3}{c}{\thead{Store vs Trash }} \\
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}
    & {I}       & {II} & {III} & {IV} & {V} & {VI} & {VII} & {VIII} & {IX} \\
    & {Coef.}
    & {\makecell[b]{Std.\\ Error}}
    & {\makecell[b]{Odds\\ ratio}}
    & {Coef.}
    & {\makecell[b]{Std.\\ Error}}
    & {\makecell[b]{Odds\\ ratio}}
    & {Coef.}
    & {\makecell[b]{Std.\\ Error}}
    & {\makecell[b]{Odds\\ ratio}} \\
\midrule
    \endhead
%%%%  
%\midrule
\multicolumn{10}{r}{\footnotesize\itshape
                    Continue on the next page}
    \endfoot
\midrule[\heavyrulewidth]
\multicolumn{10}{l}{
\textit{***p $<$ .001, ** p $<$.01, *p$<$.05, $^\wedge$ p$<$.1}
                    }
    \endlastfoot
%%%% table content
1. EPR: Yes     
    & 0.44* & 0.21  & 1.55  & 0.06  & 0.18  & 1.06  & 0.38  & 0.24  & 1.46  \\
1. LEGALAWARENESS: Yes 
    & 0.07  & 0.22  & 1.07  & -0.34 & 0.16  & 0.71  & 0.41  & 0.25  & 1.50 \\
1. LOCTAWARENESS: Maybe 
    &  1.37***  & 0.23 & 3.92 & 1.17 & 0.19 & 3.92  & 0.20  & 0.28  & 1.22 \\
2. LOCTAWARENESS: Yes 
    & 1.67***   & 0.26 & 5.30 & 1.48*** & 0.20  & 4.41  & 0.18  & 0.30  & 1.20 \\
2. IMPORTANCE: Not very 
    & -0.08 & 0.66  & 0.95 & -0.65 & 0.95  & 0.52  & 0.56  & 0.88  & 1.76 \\
3. IMPORTANCE: Neutral 
    & 1.03  & 0.58  & 2.80 & 0.25  & 0.87  & 1.28  & 0.78  & 0.82  & 2.18 \\
4. IMPORTANCE: Somewhat Important 
    & 1.95**    & 0.57  & 7.06  & -0.32 & 0.84  & 0.73  & 2.28**   & 0.80  & 9.74 \\
5. IMPORTANCE: Very Important 
    & 2.34  & 0.57  & 10.41 & 0.02  & 0.85  & 10.41 & 2.32{**}  & 0.81  & 10.17 \\
\end{longtable}%
\end{landscape}
\end{document}

Layout of table is very similar as before:

enter image description here

  • page layout: I didn't bother with it, It can be simply determined by package geometry. For example:

\documentclass[english]{article}
\usepackage[hmargin=1.25in, vmargin=1in]{geometry}
  • Third step: preamble. It is sufficient to load each package only once :). Please remove all duplicate and group them for its purpose (for tables, for units, for caption, etc)
Related Question