如何将长表格拆分成多个页面

如何将长表格拆分成多个页面

抱歉,我知道其他类似的问题已经得到解答,但我无法弄清楚如何将长表分成多行。

我有以下表格代码,但我需要将其分成两页。

\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}

答案1

  • 您的表格(您提供的代码)足够小,可以放在一页上,因此无需使用longtable:)
  • 也许你稍后会扩展它...在这种情况下,以下 mwe 可以作为框架
  • 我稍微修改了你的表格代码。在这里我使用了包booktabs(用于水平规则)和 makecell(用于多行单元格)

\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}

在此处输入图片描述 在此处输入图片描述

答案2

就是这样,通过加载makecell(允许在标准单元格中换行和使用通用格式)和booktabs(带有一些填充的可变宽度水平线)进行了简化和改进。我在行周围添加了一些间距,以提高清晰度和可读性。

我在下一页添加了一些文字来介绍表格的第二部分,但由于我不会说葡萄牙语,所以很抱歉我无法翻译它。

\documentclass[portuguese]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{array, longtable, booktabs, makecell}
\renewcommand\theadfont{\normalsize}

\begin{document}

\vspace*{8cm}

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

\end{document}

在此处输入图片描述 在此处输入图片描述

相关内容