1

I am using a journal template with roughly wide margins. I am trying to use longtable environment to split my landscape table into two pages. I also use pdfscale package. But the table does not split up, it goes outside the margins and the caption goes inside the table. I am copying my code with a few lines of the table here. Anyone can help me with this?

\begin{landscape}
\begin{longtable}
\centering
\scriptsize
\caption{The impact of the planning horizon length on LNS heuristic results for low and medium demand instances}
\begin{tabular}{|c|c||ccccc|ccccc|ccccc|}
\hline
\hline
&  &  \multicolumn{5}{c|}{$\mathcal{T}=2$ h} &   \multicolumn{5}{c|}{$\mathcal{T}=3$ h} &   \multicolumn{5}{c|}{$\mathcal{T}=4$ h}\\
Demand   &  \multirow{2}{*}{$|M|$}  &  \multirow{2}{*}{OBJ}   & \multirow{2}{*}{$|S^{\text{(u)}}|$}  & $C_{max}$ & $C_{avg}$ & $TD$   &\multirow{2}{*}{OBJ}  & \multirow{2}{*}{$|S^{\text{(u)}}|$}  & $C_{max}$ & $C_{avg}$ & $TD$   &\multirow{2}{*}{OBJ}   & \multirow{2}{*}{$|S^{\text{(u)}}|$}  & $C_{max}$ & $C_{avg}$ & $TD$   \\  
Level &   &  &  & (h) & (h) & (km)  &   &  & (h) &  (h) & (km) &   &  & (h) & (h)& (km)  \\ 
\hline
\hline
 \multirow{13}{*}{Low} & 2 & 63.93 & 10.67 & 1.95 & 0.97 & 107.67 & 74.91 & 7.67 & 2.7 & 1.23 & 132.07 & 76.17 & 3 & 3.92 & 1.86 & 195.17 \\ 
 & 3 & 48.34 & 6.67 & 1.85 & 0.9 & 135.93 & 52.81 & 2.67 & 2.83 & 1.27 & 200.03 & 50.07 & 0.33 & 3.56 & 1.51 & 235.17 \\ 
 & 4 & 38.98 & 3.33 & 1.83 & 0.85 & 171.93 & 40.09 & 0.67 & 2.75 & 1.16 & 225.37 & 37.77 & 0 & 2.74 & 1.15 & 223.33 \\ 
 & 5 & 31.83 & 1.33 & 1.71 & 0.84 & 207.7 & 31.92 & 0 & 2.32 & 0.96 & 234.13 & 30.69 & 0 & 2.14 & 0.9 & 212.3 \\
 \hline
\hline
\end{tabular}
\label{PlanningHorizon-lowMed}
\end{longtable}
\end{landscape}
4
  • \begin{longtable} ... \begin{tabular}{...} is a syntax error.
    – Mico
    Commented Mar 11, 2023 at 12:51
  • @Mico You mean should not I use these two together? But I always use table and tabular together and it works correctly.
    – sorour
    Commented Mar 11, 2023 at 12:57
  • 1
    the longtable package has a documentation which also shows a full code example. Commented Mar 11, 2023 at 13:09
  • 1
    You commented, "But I always use table and tabular together and it works correctly." Please note that I did not claim that table and tabular cannot work together. Instead, I claimed that longtable and tabular cannot work together -- and I stand by this claim. Please see my answer for an example of how to set up and employ a longtable environment. Incidentally, you mention that you use a package called pdfscale; did you mean to write pdflscape?
    – Mico
    Commented Mar 11, 2023 at 13:35

2 Answers 2

1

A tabular environment cannot span multiple pages. The longtable environment combines elements of the table and tabular environments. See the package's user guide for more details.

I would definitely give the table a more open look by getting rid of all vertical lines and by using fewer, but well-spaced, horizontal lines. Aligning the numbers in the 15 data columns on their decimal markers would also appear to be a good idea.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{longtable,pdflscape,booktabs,siunitx,amsmath}
\newcolumntype{T}[1]{S[table-format=#1]}
\newcommand\mytab[1]{\smash[b]{%
  \begin{tabular}[t]{@{}l@{}} #1 \end{tabular}}}

\begin{document}

\begin{landscape}
\setlength\tabcolsep{4pt} % default: 6pt
\setlength\LTcapwidth{\dimexpr\textwidth+3in\relax}
\small  % not "\scriptsize"}
\begin{longtable}{@{} l c 
   *{3}{T{2.2} T{2.2} T{1.2} T{3.2} T{3.2}} @{}}

%% headers and footers:

\caption{The impact of the planning horizon length on LNS heuristic 
         results for low and medium demand instances} 
\label{PlanningHorizon-lowMed} \\
\toprule
  \mytab{Demand\\Level}& $|M|$ & 
  \multicolumn{5}{c}{$\mathcal{T}=2$h} &  
  \multicolumn{5}{c}{$\mathcal{T}=3$h} &  
  \multicolumn{5}{c@{}}{$\mathcal{T}=4$h} \\
\cmidrule(lr){3-7} \cmidrule(lr){8-12} \cmidrule(l){13-17}
   & &  
   {OBJ} & $|S^{\mathrm{(u)}}|$ & $C_{\max}$ & $C_{\mathrm{avg}}$ & {$TD$} &
   {OBJ} & $|S^{\mathrm{(u)}}|$ & $C_{\max}$ & $C_{\mathrm{avg}}$ & {$TD$} &
   {OBJ} & $|S^{\mathrm{(u)}}|$ & $C_{\max}$ & $C_{\mathrm{avg}}$ & {$TD$} \\  
   & & & & {(h)} & {(h)} & {(km)} 
     & & & {(h)} & {(h)} & {(km)} 
     & & & {(h)} & {(h)} & {(km)} \\ 
\midrule
\endfirsthead 

\multicolumn{5}{@{}l}{Table \thetable, cont'd}\\[1ex]
\toprule
  \mytab{Demand\\Level}& $|M|$ & 
  \multicolumn{5}{c|}{$\mathcal{T}=2$h} &  
  \multicolumn{5}{c|}{$\mathcal{T}=3$h} &  
  \multicolumn{5}{c|}{$\mathcal{T}=4$h} \\
\cmidrule(lr){3-7} \cmidrule(lr){8-12} \cmidrule(l){13-17} 
   & &  
   {OBJ} & $|S^{\mathrm{(u)}}|$ & 
   $C_{\max}$ & $C_{\mathrm{avg}}$ & {$TD$}   &
   {OBJ} & $|S^{\mathrm{(u)}}|$ & 
   $C_{\max}$ & $C_{\mathrm{avg}}$ & {$TD$}   &
   {OBJ} & $|S^{\mathrm{(u)}}|$ & 
   $C_{\max}$ & $C_{\mathrm{avg}}$ & {$TD$}   \\  
   & & & & {(h)} & {(h)} & {(km)} 
     & & & {(h)} & {(h)} & {(km)} 
     & & & {(h)} & {(h)} & {(km)} \\ 
\midrule
\endhead

\addlinespace
\multicolumn{17}{r@{}}{\footnotesize(Cont'd on next page)} \\
\endfoot

\bottomrule
\endlastfoot


%% body of table
 Low 
 & 2 & 63.93 & 10.67& 1.95 & 0.97& 107.67 & 74.91 & 7.67 & 2.7 & 1.23 & 132.07 & 76.17 & 3   & 3.92 & 1.86 & 195.17 \\ 
 & 3 & 48.34 & 6.67 & 1.85 & 0.9 & 135.93 & 52.81 & 2.67 & 2.83& 1.27 & 200.03 & 50.07 & 0.33& 3.56 & 1.51 & 235.17 \\ 
 & 4 & 38.98 & 3.33 & 1.83 & 0.85& 171.93 & 40.09 & 0.67 & 2.75& 1.16 & 225.37 & 37.77 & 0   & 2.74 & 1.15 & 223.33 \\ 
 & 5 & 31.83 & 1.33 & 1.71 & 0.84& 207.7  & 31.92 & 0    & 2.32& 0.96 & 234.13 & 30.69 & 0   & 2.14 & 0.9  & 212.3  \\

\end{longtable}

\end{landscape}

\end{document} 
3
  • Thank you so much I appreciate your effort Mico, but I prefer to not change the appearance of the table such as getting rid of the vertical lines.
    – sorour
    Commented Mar 11, 2023 at 14:31
  • @sorour - You are of course entirely free to keep the prison cell window "look". Just do take note how to employ the longtable syntax correctly.
    – Mico
    Commented Mar 11, 2023 at 16:13
  • 1
    Got it, thank you so much Mico
    – sorour
    Commented Mar 12, 2023 at 20:30
0
  • All cells are jailed by horizontal and vertical lines (so the table is less nice)
  • Instead of longtable is used longtblr of tabularray package, consequently code is much shorter:
\documentclass{article} % or some other suitable document class
\usepackage{pdflscape}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, siunitx}


\begin{document}
\begin{landscape}

\small 
\begin{longtblr}[
caption = {The impact of the planning horizon length on LNS heuristic
         results for low and medium demand instances},
  label = {PlanningHorizon-lowMed},
                ]{hline{1,4,Z} = {0.8pt}, hline{2,3,5-Y} = {solid}, 
                  vlines,
                  colsep  = 3pt,
                  colspec = {l c
                            *{3}{X[c,si={table-format=2.2}] 
                                 X[c,si={table-format=2.2}] 
                                 X[c,si={table-format=1.2}]
                                 X[c,si={table-format=1.2}]
                                 X[c,si={table-format=3.2}]}  
                            },
                  cell{1}{3,8,13} = {c=5}{},
                  row{1-3} = {guard},
                  rowhead = 3
                  }
%% headers and footers:

\SetCell[r=3]{l}    {Demand\\Level}
    & \SetCell[r=3]{c}   $|M|$ 
        &   \SetCell[c=5]{c}   $\mathcal{T}=2$h 
            &   &   &   &   &   \SetCell[c=5]{c}   $\mathcal{T}=3$h    
                                &   &   &   &   &   \SetCell[c=5]{c}   $\mathcal{T}=4$h
                                                    &   &   &   &   \\
    \midrule
    &   &   OBJ
            &   $|S^{\mathrm{(u)}}|$ 
                &   $C_{\max}$ 
                    &   $C_{\mathrm{avg}}$ 
                        & {$TD$} 
        &   OBJ
            &   $|S^{\mathrm{(u)}}|$
                &   $C_{\max}$
                    &   $C_{\mathrm{avg}}$
                        &   {$TD$}
        &   OBJ
            &   $|S^{\mathrm{(u)}}|$
                &   $C_{\max}$
                    &   $C_{\mathrm{avg}}$
                        &   $TD$                                    \\
    &   &   &   &   (h) &   (h) &   (km) 
    &   &   &   (h) &   (h) &   (km)
    &   &   &   (h) &   (h) &   (km)                                \\
%%% body of table
Low & 2 
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67 
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07 
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\
    & 3 
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93 
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03 
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\
    & 4 
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93 
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37 
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\
    & 5     
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7 
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\
Low & 2 % repeated
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\*
    & 3
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\*
    & 4
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\*
    & 5
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\

Low & 2 % repeated
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\*
    & 3
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\*
    & 4
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\*
    & 5
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\

Low & 2 % repeated
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\*
    & 3
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\*
    & 4
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\*
    & 5
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\

Low & 2 % repeated
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\*
    & 3
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\*
    & 4
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\*
    & 5
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\

Low & 2 % repeated
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\*
    & 3
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\*
    & 4
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\*
    & 5
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\

Low & 2 % repeated
    & 63.93 & 10.67 & 1.95  & 0.97  & 107.67
    & 74.91 & 7.67  & 2.7   & 1.23  & 132.07
    & 76.17 & 3     & 3.92  & 1.86  & 195.17                        \\*
    & 3
    & 48.34 & 6.67  & 1.85  & 0.9   & 135.93
    & 52.81 & 2.67  & 2.83  & 1.27  & 200.03
    & 50.07 & 0.33  & 3.56  & 1.51  & 235.17                        \\*
    & 4
    & 38.98 & 3.33  & 1.83  & 0.85  & 171.93
    & 40.09 & 0.67  & 2.75  & 1.16  & 225.37
    & 37.77 & 0     & 2.74  & 1.15  & 223.33                        \\*
    & 5
    & 31.83 & 1.33  & 1.71  & 0.84  & 207.7
    & 31.92 & 0     & 2.32  & 0.96  & 234.13
    & 30.69 & 0     & 2.14  & 0.9   & 212.3                         \\
\end{longtblr}

\end{landscape}
\end{document} 

enter image description here

You must log in to answer this question.

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