2

I have a longtable whose header is coming in the previous page instead of the next page. The table is long as well, I tried manually placing \pagebreak to no benefit. Please help why this happening?!

\documentclass{article}
\usepackage{graphicx} % Required for inserting images

\title{trial}
\usepackage{longtable, booktabs}

\begin{document}

%\maketitle

{\scriptsize\tabcolsep = 1.9pt 
\renewcommand\arraystretch{2.1}
\begin{longtable}{@{\extracolsep{1.5pt}}ccccccccccc@{}}
\caption{Trial.}\\
\hline
value & \multicolumn{5}{c}{value} & \multicolumn{5}{c}{value}  \\ 
   \cline{2-6} \cline{7-11}  
  & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} &  value & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} & value \\
 \cline{2-3} \cline{4-5} \cline{7-8}  \cline{9-10} 
  & value & value & value & value & & value & value & value & value &   \\
 \hline
\endfirsthead
\caption{Trial.}\\
\hline
value &   \multicolumn{5}{c}{value} & \multicolumn{5}{c}{value}  \\ 
   \cline{2-6} \cline{7-11}  
  & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} &  value & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} & value \\
 \cline{2-3} \cline{4-5} \cline{7-8}  \cline{9-10} 
  & value & value & value & value & & value & value & value & value &   \\
 \hline
\midrule
   \multicolumn{11}{r}{\footnotesize\itshape Continued on the next page}
\endfoot
\endlastfoot
1 & - & - & - & - & - & - & - & - & - & - \\ 
2 & - & - & - & - & - & - & - & - & - & - \\ 
3 & - & - & - & - & - & - & - & - & - & - \\ 
4 & - & - & - & - & - & - & - & - & - & - \\ 
5 & - & - & - & - & - & - & - & - & - & - \\ 
6 & - & - & - & - & - & - & - & - & - & - \\ 
7 & - & - & - & - & - & - & - & - & - & - \\ 
8 & - & - & - & - & - & - & - & - & - & - \\ 
9 & - & - & - & - & - & - & - & - & - & - \\ 
1 & - & - & - & - & - & - & - & - & - & - \\ 
2 & - & - & - & - & - & - & - & - & - & - \\ 
3 & - & - & - & - & - & - & - & - & - & - \\ 
4 & - & - & - & - & - & - & - & - & - & - \\ 
5 & - & - & - & - & - & - & - & - & - & - \\ 
6 & - & - & - & - & - & - & - & - & - & - \\ 
7 & - & - & - & - & - & - & - & - & - & - \\ 
8 & - & - & - & - & - & - & - & - & - & - \\ 
9 & - & - & - & - & - & - & - & - & - & - \\ 
1 & - & - & - & - & - & - & - & - & - & - \\ 
2 & - & - & - & - & - & - & - & - & - & - \\ 
3 & - & - & - & - & - & - & - & - & - & - \\ 
4 & - & - & - & - & - & - & - & - & - & - \\ 
5 & - & - & - & - & - & - & - & - & - & - \\ 
6 & - & - & - & - & - & - & - & - & - & - \\ 
7 & - & - & - & - & - & - & - & - & - & - \\ 
8 & - & - & - & - & - & - & - & - & - & - \\ 
9 & - & - & - & - & - & - & - & - & - & - \\ 
1 & - & - & - & - & - & - & - & - & - & - \\ 
2 & - & - & - & - & - & - & - & - & - & - \\ 
3 & - & - & - & - & - & - & - & - & - & - \\ 
4 & - & - & - & - & - & - & - & - & - & - \\ 
5 & - & - & - & - & - & - & - & - & - & - \\ 
6 & - & - & - & - & - & - & - & - & - & - \\ 
7 & - & - & - & - & - & - & - & - & - & - \\ 
8 & - & - & - & - & - & - & - & - & - & - \\ 
9 & - & - & - & - & - & - & - & - & - & - \\ 
\end{longtable}
}

\end{document}

enter image description here

enter image description here

3
  • 2
    there are some issues with longtable page breaking but I've never seen that. please make a small reproducible example so that it can be debugged Dec 24, 2023 at 11:33
  • I edited the question with the code, I just added multiple rows so that it extends to multiple pages. Dec 24, 2023 at 12:08
  • you have specified the caption goes in the foot not the head. Dec 24, 2023 at 12:16

2 Answers 2

4
\caption{Trial.}\\
\hline
value & \multicolumn{5}{c}{value} & \multicolumn{5}{c}{value}  \\ 
    \cline{2-6} \cline{7-11}  
   & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} &  value & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} & value \\
  \cline{2-3} \cline{4-5} \cline{7-8}  \cline{9-10} 
   & value & value & value & value & & value & value & value & value &   \\
  \hline
\endfirsthead

specifies table headings on the first page

\caption{Trial.}\\
\hline
value &   \multicolumn{5}{c}{value} & \multicolumn{5}{c}{value}  \\ 
    \cline{2-6} \cline{7-11}  
   & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} &  value & \multicolumn{2}{c}{value} & \multicolumn{2}{c}{value} & value \\
  \cline{2-3} \cline{4-5} \cline{7-8}  \cline{9-10} 
   & value & value & value & value & & value & value & value & value &   \\
  \hline
\midrule
    \multicolumn{11}{r}{\footnotesize\itshape Continued on the next page}
\endfoot

specifies the table footer on all pages except the last

\endlastfoot

specifies an empty footer on the last page.

So on the first page you get the caption and table column headings at the top and bottom.

I would guess you intended \endhead after the \midrule before \endfoot

1
1

More simple and robust to errors in column headers and captions code you can get by use of the tabularray instead longtable package. Beside this since you load ˙booktabs` package it is sensible to use rules defined by it:

\documentclass{article}
\usepackage{tabularray} 
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{longtblr}[ % defined in tabularray package
caption = {Trial.},
  label = {longtab:trial}
                    ]{colspec = {@{} c *{10}{X[c]} @{}},
                      cell{1}{2,7} = {c=5}{},
                      cell{2}{2,4,7,9} = {c=2}{},
                      rowhead = 1
                      }
% column headers
    \toprule
value   &   value
            &   &   &   &   &   value
                                &   &   &   &   \\
    \cmidrule[lr]{2-6}  \cmidrule[l]{7-11}
        &   value
            &   &   value
                    &   value
                        &   value
                            &   value
                                &   value
                                    &   value
                                        &   value
                                            &   value   \\
    \cmidrule[lr]{2-3}  \cmidrule[lr]{4-5}
    \cmidrule[lr]{7-8}  \cmidrule[lr]{9-10}
    &   value 
        &   value 
            &   value 
                &   value 
                    &   &   value 
                            &   value 
                                &   value 
                                    &   value   &       \\
    \midrule
% table body
1   & - & - & - & - & - & - & - & - & - & - \\
2   & - & - & - & - & - & - & - & - & - & - \\
3   & - & - & - & - & - & - & - & - & - & - \\
4   & - & - & - & - & - & - & - & - & - & - \\
5   & - & - & - & - & - & - & - & - & - & - \\
6   & - & - & - & - & - & - & - & - & - & - \\
7   & - & - & - & - & - & - & - & - & - & - \\
8   & - & - & - & - & - & - & - & - & - & - \\
9   & - & - & - & - & - & - & - & - & - & - \\

1   & - & - & - & - & - & - & - & - & - & - \\
2   & - & - & - & - & - & - & - & - & - & - \\
3   & - & - & - & - & - & - & - & - & - & - \\
4   & - & - & - & - & - & - & - & - & - & - \\
5   & - & - & - & - & - & - & - & - & - & - \\
6   & - & - & - & - & - & - & - & - & - & - \\
7   & - & - & - & - & - & - & - & - & - & - \\
8   & - & - & - & - & - & - & - & - & - & - \\
9   & - & - & - & - & - & - & - & - & - & - \\

1   & - & - & - & - & - & - & - & - & - & - \\
2   & - & - & - & - & - & - & - & - & - & - \\
3   & - & - & - & - & - & - & - & - & - & - \\
4   & - & - & - & - & - & - & - & - & - & - \\
5   & - & - & - & - & - & - & - & - & - & - \\
6   & - & - & - & - & - & - & - & - & - & - \\
7   & - & - & - & - & - & - & - & - & - & - \\
8   & - & - & - & - & - & - & - & - & - & - \\
9   & - & - & - & - & - & - & - & - & - & - \\

1   & - & - & - & - & - & - & - & - & - & - \\
2   & - & - & - & - & - & - & - & - & - & - \\
3   & - & - & - & - & - & - & - & - & - & - \\
4   & - & - & - & - & - & - & - & - & - & - \\
5   & - & - & - & - & - & - & - & - & - & - \\
6   & - & - & - & - & - & - & - & - & - & - \\
7   & - & - & - & - & - & - & - & - & - & - \\
8   & - & - & - & - & - & - & - & - & - & - \\
9   & - & - & - & - & - & - & - & - & - & - \\
    \bottomrule
    \end{longtblr}
\end{document}

Syntax of tabularray package is thoroughly described in the package documentation.

enter image description here

(red lines shows page layout)

You must log in to answer this question.

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