将表转换为 LongTable

将表转换为 LongTable

我需要将下面的表格转换为长表。我查看了本网站中与此问题相关的其他主题。我删除了\begin{table}\end{table}标签,还将所有标签替换为\begin{tabular}\begin{longtable}。但它仍然不起作用。如果有人能帮助我将不胜感激...\end{tabular}\end{longtable}

我正在将原始表格复制到这里。

注意:我正在使用\usepackage{longtable}

\begin{table}[h]
    \begin{tabular}{c|rrrrrrc|}
        \cline{2-8}
        \multicolumn{1}{l|}{}                                                                                                                       & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Tr.\\ set\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Acc.\\ (\%)\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Rec.\\ (\%)\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Pre.\\ (\%)\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}F-msr\\ (\%)\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}\#of \\ Leaves\end{tabular}}} & \cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Used\\ Ftrs\\ by C4.5\end{tabular}}                           \\ \hline
            \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}60.6}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}88.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}56.8}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}69.1}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}5}                                                               & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ ip.proto\\ push flag\end{tabular}                                          \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{49.5}                                                                                 & \multicolumn{1}{r|}{99.0}                                                                                 & \multicolumn{1}{r|}{50.0}                                                                                 & \multicolumn{1}{r|}{66.2}                                                                                  & \multicolumn{1}{r|}{8}                                                                                       & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ frame.caplen\\ push flag\end{tabular}                                      \\ \cline{2-8} 
           \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}65.1}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}30.2}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}100}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}46.5}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}1800}                                                            & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ ip.proto\\ push flag\\ frame.len\end{tabular}                                  \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}All\\ Ftrs\end{tabular}}}}                 & \multicolumn{1}{r|}{\textit{D4}}                                                                        & \multicolumn{1}{r|}{81.1}                                                                                 & \multicolumn{1}{r|}{81.9}                                                                                 & \multicolumn{1}{r|}{61.8}                                                                                 & \multicolumn{1}{r|}{70.4}                                                                                  & \multicolumn{1}{r|}{29}                                                                                      & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ ip.ttl\\ frame.len\\ frame.deltatime\end{tabular}                              \\ \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}24.2}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}29.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}26.6}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}28.0}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}5}                                                               & \begin{tabular}[c]{@{}c@{}}ip.proto\\ frame.len\\ ack flag\end{tabular}                                                  \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{50.0}                                                                                 & \multicolumn{1}{r|}{60.0}                                                                                 & \multicolumn{1}{r|}{50.0}                                                                                 & \multicolumn{1}{r|}{54.5}                                                                                  & \multicolumn{1}{r|}{25}                                                                                      & \begin{tabular}[c]{@{}c@{}}ip.ttl\\ ip.proto\\ frame.len\\ frame.deltatime\\ ack flag\end{tabular}                       \\ \cline{2-8} 
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}60.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}23.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}99.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}37.3}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}390}                                                             & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ syn flag\\ res flag\end{tabular}                                         \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Exp. \\ based\\ Ftrs\end{tabular}}}}       & \multicolumn{1}{r|}{\textit{D4}}                                                                        & \multicolumn{1}{r|}{88.2}                                                                                 & \multicolumn{1}{r|}{80.0}                                                                                 & \multicolumn{1}{r|}{95.7}                                                                                 & \multicolumn{1}{r|}{87.2}                                                                                  & \multicolumn{1}{r|}{97}                                                                                      & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag\end{tabular} \\ \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}72.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}88.1}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}66.8}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}76.0}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}5}                                                               & \begin{tabular}[c]{@{}c@{}}ip.proto\\ frame.len\end{tabular}                                                             \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{49.0}                                                                                 & \multicolumn{1}{r|}{90.0}                                                                                 & \multicolumn{1}{r|}{47.7}                                                                                 & \multicolumn{1}{r|}{62.4}                                                                                  & \multicolumn{1}{r|}{14}                                                                                      & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ frame.caplen\\ ip.ttl\\ ip.proto\end{tabular}                              \\ \cline{2-8} 
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.7}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}78.5}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}95.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.1}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}164}                                                             & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ frame.len\\ ip.ttl\end{tabular}                                                \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Chi\\ Squ-\\ ared\\ Ftrs\end{tabular}}}}   & \multicolumn{1}{r|}{\textit{D4}}                                                                        & \multicolumn{1}{r|}{88.2}                                                                                 & \multicolumn{1}{r|}{80.0}                                                                                 & \multicolumn{1}{r|}{95.7}                                                                                 & \multicolumn{1}{r|}{87.2}                                                                                  & \multicolumn{1}{r|}{97}                                                                                      & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag\end{tabular} \\ \hline
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}48.8}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}76.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}46.4}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}60.6}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}4}                                                               & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ ecn flag\end{tabular}                                                      \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{50.1}                                                                                 & \multicolumn{1}{r|}{80.2}                                                                                 & \multicolumn{1}{r|}{51.5}                                                                                 & \multicolumn{1}{r|}{62.8}                                                                                  & \multicolumn{1}{r|}{9}                                                                                       & \begin{tabular}[c]{@{}c@{}}ip.proto\\ icmp.type\\ ns flag\end{tabular}                                                   \\ \cline{2-8} 
        \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.7}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}78.5}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}95.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.1}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}164}                                                             & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ frame.len\\ ip.ttl\end{tabular}                                                \\ \cline{2-8} 
        \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Sym.\\ Unc.\\ based\\ Ftrs\end{tabular}}}} & \textit{D4}                                                                                             & 88.2                                                                                                      & 80.0                                                                                                      & 95.7                                                                                                      & 87.2                                                                                                       & 97                                                                                                           & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag\end{tabular} \\ \hline
    \end{tabular}
\end{table}

答案1

您需要 (a) 删除现有的table“包装器”,(b) 将外部tabular环境转换为longtable环境,以及 (c) 使用\endhead\endlastfoot分别设置属于页眉和页脚的材料。

下面的截图仅显示标题行和前两行数据。

在此处输入图片描述

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow,longtable}
\begin{document}

\begin{longtable}{c|rrrrrrc|}
\cline{2-8}
& \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Tr.\\ set\end{tabular}}} 
& \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Acc.\\ (\%)\end{tabular}}} 
& \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Rec.\\ (\%)\end{tabular}}} 
& \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Pre.\\ (\%)\end{tabular}}} 
& \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}F-msr\\ (\%)\end{tabular}}} 
& \multicolumn{1}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}\# of \\ Leaves\end{tabular}}} 
& \cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Used\\ Ftrs\\ by C4.5\end{tabular}} \\ 
\hline
\endhead
\hline
\endlastfoot
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}60.6}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}88.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}56.8}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}69.1}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}5}                                                               & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ ip.proto\\ push flag\end{tabular}                                          \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{49.5}                                                                                 & \multicolumn{1}{r|}{99.0}                                                                                 & \multicolumn{1}{r|}{50.0}                                                                                 & \multicolumn{1}{r|}{66.2}                                                                                  & \multicolumn{1}{r|}{8}                                                                                       & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ frame.caplen\\ push flag\end{tabular}                                      \\ \cline{2-8} 
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}65.1}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}30.2}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}100}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}46.5}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}1800}                                                            & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ ip.proto\\ push flag\\ frame.len\end{tabular}                                  \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}All\\ Ftrs\end{tabular}}}}                 & \multicolumn{1}{r|}{\textit{D4}}                                                                        & \multicolumn{1}{r|}{81.1}                                                                                 & \multicolumn{1}{r|}{81.9}                                                                                 & \multicolumn{1}{r|}{61.8}                                                                                 & \multicolumn{1}{r|}{70.4}                                                                                  & \multicolumn{1}{r|}{29}                                                                                      & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ ip.ttl\\ frame.len\\ frame.deltatime\end{tabular}                              \\ \hline
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}24.2}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}29.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}26.6}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}28.0}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}5}                                                               & \begin{tabular}[c]{@{}c@{}}ip.proto\\ frame.len\\ ack flag\end{tabular}                                                  \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{50.0}                                                                                 & \multicolumn{1}{r|}{60.0}                                                                                 & \multicolumn{1}{r|}{50.0}                                                                                 & \multicolumn{1}{r|}{54.5}                                                                                  & \multicolumn{1}{r|}{25}                                                                                      & \begin{tabular}[c]{@{}c@{}}ip.ttl\\ ip.proto\\ frame.len\\ frame.deltatime\\ ack flag\end{tabular}                       \\ \cline{2-8} 
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}60.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}23.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}99.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}37.3}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}390}                                                             & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ syn flag\\ res flag\end{tabular}                                         \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Exp. \\ based\\ Ftrs\end{tabular}}}}       & \multicolumn{1}{r|}{\textit{D4}}                                                                        & \multicolumn{1}{r|}{88.2}                                                                                 & \multicolumn{1}{r|}{80.0}                                                                                 & \multicolumn{1}{r|}{95.7}                                                                                 & \multicolumn{1}{r|}{87.2}                                                                                  & \multicolumn{1}{r|}{97}                                                                                      & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag\end{tabular} \\ \hline
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}72.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}88.1}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}66.8}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}76.0}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}5}                                                               & \begin{tabular}[c]{@{}c@{}}ip.proto\\ frame.len\end{tabular}                                                             \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{49.0}                                                                                 & \multicolumn{1}{r|}{90.0}                                                                                 & \multicolumn{1}{r|}{47.7}                                                                                 & \multicolumn{1}{r|}{62.4}                                                                                  & \multicolumn{1}{r|}{14}                                                                                      & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ frame.caplen\\ ip.ttl\\ ip.proto\end{tabular}                              \\ \cline{2-8} 
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.7}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}78.5}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}95.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.1}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}164}                                                             & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ frame.len\\ ip.ttl\end{tabular}                                                \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Chi\\ Squ-\\ ared\\ Ftrs\end{tabular}}}}   & \multicolumn{1}{r|}{\textit{D4}}                                                                        & \multicolumn{1}{r|}{88.2}                                                                                 & \multicolumn{1}{r|}{80.0}                                                                                 & \multicolumn{1}{r|}{95.7}                                                                                 & \multicolumn{1}{r|}{87.2}                                                                                  & \multicolumn{1}{r|}{97}                                                                                      & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag\end{tabular} \\ \hline
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D1}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}48.8}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}76.0}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}46.4}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}60.6}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}4}                                                               & \begin{tabular}[c]{@{}c@{}}ip.checksum\_bad\\ ecn flag\end{tabular}                                                      \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\textit{D2}}                                                                        & \multicolumn{1}{r|}{50.1}                                                                                 & \multicolumn{1}{r|}{80.2}                                                                                 & \multicolumn{1}{r|}{51.5}                                                                                 & \multicolumn{1}{r|}{62.8}                                                                                  & \multicolumn{1}{r|}{9}                                                                                       & \begin{tabular}[c]{@{}c@{}}ip.proto\\ icmp.type\\ ns flag\end{tabular}                                                   \\ \cline{2-8} 
\rowcolor[HTML]{EFEFEF} 
  \multicolumn{1}{|c|}{\cellcolor[HTML]{C0C0C0}}                                                                                              & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}\textit{D3}}                                                & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.7}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}78.5}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}95.3}                                                         & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}86.1}                                                          & \multicolumn{1}{r|}{\cellcolor[HTML]{EFEFEF}164}                                                             & \begin{tabular}[c]{@{}c@{}}frame.caplen\\ frame.len\\ ip.ttl\end{tabular}                                                \\ \cline{2-8} 
  \multicolumn{1}{|c|}{\multirow{-4}{*}{\cellcolor[HTML]{C0C0C0}\textbf{\begin{tabular}[c]{@{}c@{}}Sym.\\ Unc.\\ based\\ Ftrs\end{tabular}}}} & \textit{D4}                                                                                             & 88.2                                                                                                      & 80.0                                                                                                      & 95.7                                                                                                      & 87.2                                                                                                       & 97                                                                                                           & \begin{tabular}[c]{@{}c@{}}frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag\end{tabular} \\ 
\end{longtable}
\end{document}

附录: 顺便说一下,不是有必要将每个单元格都包裹在\multicolumn{..}{...}包装器中。事实上,如果您避免这种做法,代码的可读性将大大提高。另外,与环境[c]的默认位置一样tabular,您不需要指定它。此外,我将定义一个宏(\mytab在下面的代码中调用)来简化输入所有\begin{tabular} ... \end{tabular}代码块(其中有二十多个)。最后,由于您交替使用浅灰色和白色行颜色,因此指令\cline不会做太多事情——我会完全省略它们。我也会省略所有内部垂直条;相信我,它们不会被遗漏。

在此处输入图片描述

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow,longtable}

% define a few shortcut macros
\newcommand\mygray{\rowcolor[HTML]{EFEFEF}}
\newcommand\mydgray{\cellcolor[HTML]{C0C0C0}}
\newcommand\Tstrut{\rule{0pt}{2.5ex}} % typographic "top" strut
\newcommand\mytab[1]{\begin{tabular}{@{}c@{}} \Tstrut #1 \end{tabular}}

\begin{document}

\begin{longtable}{ |c| >{\itshape}c rrrrr c | }

%% define longtable headers and footers:

\cline{2-8}
\rowcolor[HTML]{C0C0C0}
\multicolumn{1}{c|}{\cellcolor[HTML]{FFFFFF} {}} % blank cell
& \textbf{\upshape\mytab{Tr.\\ set}}
& \textbf{\mytab{Acc.\\ (\%)}}
& \textbf{\mytab{Rec.\\ (\%)}}
& \textbf{\mytab{Pre.\\ (\%)}}
& \textbf{\mytab{F-msr\\ (\%)}}
& \textbf{\mytab{\# of\\ Leaves}}
& \textbf{\mytab{Used\\ Ftrs\\ by C4.5}} \\ 
\hline
\endhead

\hline
\endfoot


%% body of table:

\mygray \mydgray
  & D1 & 60.6 & 88.3 & 56.8 & 69.1 & 5
  & \mytab{ip.checksum\_bad\\ ip.proto\\ push flag} \\ 
\mydgray
  & D2 & 49.5 & 99.0 & 50.0 & 66.2 & 8 
  & \mytab{ip.checksum\_bad\\ frame.caplen\\ push flag} \\  
\mygray \mydgray
  & D3 & 65.1 & 30.2 & 100 & 46.5 & 1800
  & \mytab{frame.caplen\\ ip.proto\\ push flag\\ frame.len} \\ 
\multirow{-10}{*}{\mydgray\textbf{\mytab{All\\ Ftrs}}}               
  & D4 & 81.1 & 81.9 & 61.8 & 70.4 & 29
  & \mytab{frame.caplen\\ ip.ttl\\ frame.len\\ frame.deltatime} \\ 
\hline
\mygray \mydgray
  & D1 & 24.2 & 29.3 & 26.6 & 28.0 & 5 
  & \mytab{ip.proto\\ frame.len\\ ack flag} \\ 
\mydgray
  & D2 & 50.0 & 60.0 & 50.0 & 54.5 & 25
  & \mytab{ip.ttl\\ ip.proto\\ frame.len\\ frame.deltatime\\ ack flag} \\ 
\mygray \mydgray
  & D3 & 60.0 & 23.0 & 99.0 & 37.3 & 390
  & \mytab{frame.len\\ ip.ttl\\ syn flag\\ res flag} \\ 
\multirow{-14}{*}{\mydgray\textbf{\mytab{Exp. \\ based\\ Ftrs}}}       
  & D4 & 88.2 & 80.0 & 95.7 & 87.2 & 97
  & \mytab{frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag} \\ 
\hline
\mygray \mydgray
  & D1 & 72.0 & 88.1 & 66.8 & 76.0 & 5
  & \mytab{ip.proto\\ frame.len} \\  
\mydgray
  & D2 & 49.0 & 90.0 & 47.7 & 62.4 & 14 
  & \mytab{ip.checksum\_bad\\ frame.caplen\\ ip.ttl\\ ip.proto} \\  
\mygray  
\mydgray
  & D3 & 86.7 & 78.5 & 95.3 & 86.1 & 164
  & \mytab{frame.caplen\\ frame.len\\ ip.ttl} \\ 
\multirow{-7}{*}{\mydgray\textbf{\mytab{Chi\\ Sqrd\\ Ftrs}}}  
  & D4 & 88.2 & 80.0 & 95.7 & 87.2 & 97
  & \mytab{frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag} \\ 
\hline
\mygray 
\mydgray
  & D1 & 48.8 & 76.0 & 46.4 & 60.6 & 4
  & \mytab{ip.checksum\_bad\\ ecn flag} \\ 
\mydgray
  & D2 & 50.1 & 80.2 & 51.5 & 62.8 & 9
  & \mytab{ip.proto\\ icmp.type\\ ns flag} \\  
\mygray 
\mydgray
  & D3 & 86.7 & 78.5 & 95.3 & 86.1 & 164
  & \mytab{frame.caplen\\ frame.len\\ ip.ttl} \\ 
\multirow{-11}{*}{\mydgray\textbf{\mytab{Sym.\\ Unc.\\ based\\ Ftrs}}} 
  & D4 & 88.2 & 80.0 & 95.7 & 87.2 & 97 
  & \mytab{frame.len\\ ip.ttl\\ frame.deltatime\\ syn flag\\ ip.proto\\ ack flag\\ res flag} \\ 
  
\end{longtable}

\end{document}

答案2

首先添加

\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{multirow}

到你的序言中,然后替换

\begin{table}[h]
\begin{tabular}

经过

\setlongtables
\begin{longtable}

\end{tabular}
\end{table}

经过

\end{longtable}

相关内容