[Tex/LaTex] How to split long table in multiple pages

longtabletables

Sorry, I know that other questions similar to this one were answered but I was not able to figure out how to split a long table in multiple lines.

I have the following code for a table but I need to split it in two pages.

\begin{document}

\begin{table}[h]

\centering
\caption{Comparação dos resultados obtidos.}
\label{comp}
\begin{tabular}{ccccccc}
    \hline
    Teste & \begin{tabular}[c]{@{}c@{}}Maior\\ resultado (\%)\end{tabular} & 

\begin{tabular}[c]{@{}c@{}}N\\ (NoC)\end{tabular}  & Tipo & \begin{tabular}[c]{@{}c@{}}Característca\\ extraída\end{tabular} & \begin{tabular}[c]{@{}c@{}}Rotina\\de ML\end{tabular}& \begin{tabular}[c]{@{}l@{}}Conversão para\\ níveis de cinza\end{tabular} \\
\hline
1 & 67,5000 & 6 (24) & Haar & Energia & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:pratt}\\ 
        2 & 67,5000 & 6 (24) & Haar & Energia & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:customeq} \\  
        3 & 65,9167 & \begin{tabular}[c]{@{}c@{}} 3 (12)\\ 4 (16) \end{tabular} & db4 & Energia & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:pratt}\\
        4 & 66,8333 & 4 (16) & db4 & Energia & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:customeq}\\
        5 & 67,5833 & 5 (40) & Haar & Energia e Std & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:pratt}\\
        6 & 67,5000 & \begin{tabular}[c]{@{}c@{}} 4 (32)\\ 5 (40) \end{tabular} & Haar & Energia e Std & \begin{tabular}[c]{@{}c@{}}IBk\\  \textit{cross-validation}\end{tabular} & eq. \ref{eq:customeq}\\
        7 & 68,6667 & 2 (16) & db4 & Energia e Std  & \begin{tabular}[c]{@{}c@{}}IBk\\ 
        \textit{percentage split}\end{tabular}& eq. \ref{eq:pratt}\\
        8 & 68,3333 & \begin{tabular}[c]{@{}c@{}} 2 (16)\\ 3 (24) \end{tabular} & db4 & Energia e Std & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\\ \textit{percentage split}\end{tabular} & eq. \ref{eq:customeq}\\
        9 & 71,0000 & 3 (33) & db16 & \begin{tabular}[c]{@{}c@{}}Energia, Std\\e entropia\end{tabular}  & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:pratt} \\
        10 & 71,0833 & 3 (33) & db16 & \begin{tabular}[c]{@{}c@{}}Energia, Std\\e entropia\end{tabular}  & \begin{tabular}[c]{@{}c@{}}IBk\\ \textit{cross-validation}\end{tabular} & eq. \ref{eq:customeq}\\

\hline

\end{tabular}
\end{table}
\end{document}

Best Answer

  • your table (which code you provide) is small enough that can fit on one page, so there is no need to use longtable :)
  • maybe you will expand it later ... in this case the following mwe can serve as framework
  • i slightly modify your table code. in this i employ packages booktabs (for horizontal rules) and makecell (for multi line cells)

\documentclass{article}
\usepackage{geometry}

\usepackage[utf8]{inputenc}
\usepackage{booktabs, makecell, longtable}

\usepackage{lipsum}
\begin{document}
\lipsum[1-3]

\begin{longtable}{cc cc cc c}
    \caption{Comparação dos resultados obtidos.}
    \label{comp}        \\
    \toprule
Teste
    &   \makecell[b]{Maior\\ resultado (\%)}
        &   \makecell[b]{N\\ (NoC)}    &   Tipo
            &   \makecell[b]{Característca\\ extraída}
                &   \makecell[b]{Rotina\\de ML}
                    &   \makecell[b]{Conversão para\\ níveis de cinza}  \\
    \midrule
\endfirsthead
    \caption[]{Comparação dos resultados obtidos (cont.).}    \\
    \toprule
Teste
    &   \makecell[b]{Maior\\ resultado (\%)}
        &   \makecell[b]{N\\ (NoC)}    &   Tipo
            &   \makecell[b]{Característca\\ extraída}
                &   \makecell[b]{Rotina\\de ML}
                    &   \makecell[b]{Conversão para\\ níveis de cinza}  \\
    \midrule
\endhead
    \midrule
    \multicolumn{7}{r}{\footnotesize\itshape Continue on the next page}
\endfoot
    \bottomrule
\endlastfoot
1 & 67,5000 & 6 (24) & Haar & Energia & \makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:pratt}
    \\  \addlinespace[5pt]
2 & 67,5000 & 6 (24) & Haar & Energia & \makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:customeq}
    \\  \addlinespace[5pt]
3 & 65,9167 & \makecell{3 (12)\\ 4 (16)} & db4 & Energia & \makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:pratt}
    \\  \addlinespace[5pt]
4 & 66,8333 & 4 (16) & db4 & Energia & \makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:customeq}
    \\  \addlinespace[5pt]
5 & 67,5833 & 5 (40) & Haar & Energia e Std & \makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:pratt}
    \\  \addlinespace[5pt]
6 & 67,5000 & \makecell{4 (32)\\ 5 (40)} & Haar & Energia e Std & \makecell{IBk\\  \textit{cross-validation}} & eq. \ref{eq:customeq}
    \\  \addlinespace[5pt]
7 & 68,6667 & 2 (16) & db4 & Energia e Std  & \makecell{IBk\\ \textit{percentage split}} & eq. \ref{eq:pratt}
    \\    \addlinespace[5pt]
8 & 68,3333 & \makecell{ 2 (16)\\ 3 (24)} & db4 & Energia e Std & \makecell{IBk\\ \textit{cross-validation}\\ \textit{percentage split}} & eq. \ref{eq:customeq}
    \\  \addlinespace[5pt]
9 & 71,0000 & 3 (33) & db16 & \makecell{Energia, Std\\e entropia}  & \makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:pratt}
    \\    \addlinespace[5pt]
10 & 71,0833 & 3 (33) & db16 & \makecell{Energia, Std\\e entropia}  &
\makecell{IBk\\ \textit{cross-validation}} & eq. \ref{eq:customeq}
    \\
\end{longtable}
\end{document}

enter image description here enter image description here

Related Question