longtable-表头或表尾不在表的开始处

longtable-表头或表尾不在表的开始处

我有一张长表,在以下行产生错误(“表头或表尾不在表的开头”)\endlastfoot:。

我不知道问题出在哪里。我将非常感激任何见解。

我的代码如下(我减少了行数)

\begin{center}
\begin{longtable}{|c|c|c|c|c|c|c|c|c|c|c|p{}|}
\caption{Title}
\label{}
\\
\hline {d} & {W} & {R} &  {S} & {D} & {C1} & {C2} & {C3} & {A} & {N}\\
\endfirsthead
\hline\multicolumn{11}{|c|}
{{ \tablename \ \thetable{}--continued from previous page}}\\
\hline {d} & {W} & {R} &  {S} & {D} & {C1} & {C2} & {C3} & {A} & {N}\\
\endhead
\hline\multicolumn{11}{|c|}{{continued on next page}}\\
\hline
\endfoot
\hline
0 & 1 & 2 & 0 & 0 &  1 & 0 & 0 & 0 & 0 \\ \cline{1-11}
1 & 1 & 2.3476 & 1.4393 & 0.1864 &  0.8541 & 0.1459 & 0 & 0 & 0.0267 \\ \hline

\endlastfoot
\end{longtable}
\end{center}

该表仍然产生错误:

\begin{longtable}{|c|c|c|c|c|p{}|} 
\caption{}
\label{Spearman and distance correlation}
\\\hline{\small G} & {\small B)} &  {\small B} & {\small S (Group C)} & {\small  D} \\
\endfirsthead
\hline\multicolumn{5}{|c|}
{{ \tablename \ \thetable{} continued from previous page}}\\
\hline{\small G} & {\small B)} &  {\small B} & {\small S (Group C)} & {\small  D} \\
\hline
\endhead
\hline\multicolumn{5}{|c|}{{continued on next page}}\\
\hline
\endfoot
\hline
 TR & & & 0.64711267 & 0.6899505 \\\cline{1-5}
        CGR & 0.6605117 & 0.67962766 & &  \\\cline{1-5}
        C2 & 0.60588574 & 0.58207303 & &\\ \cline{1-5}
        C1 & 0.7528371 & 0.75355834 & 0.8530607 & 0.82074517 \\\cline{1-5}
        C2 & & & 0.65749854 & 0.63852245\\ \cline{1-5}
        CR & & & 0.61507607 & 0.63170303\\ \cline{1-5}
        IA1 & 0.56433934 & 0.5921317 & &\\ \cline{1-5}
        IR & 0.84881425 & 0.8601397 & & \\ \cline{1-5}
        I& 0.8097711 & 0.834002 & &\\ \cline{1-5}
        HSD17B1 vs IGF1R & 0.68974805 & 0.7168968 & & \\\cline{1-5}
        HGR & 0.62358147 & 0.6271943 & & \\\cline{1-5}
        HX & & & 0.61812353 & 0.65268934\\ \cline{1-5}
        H3 & & & 0.8229002 & 0.8185904 \\ \cline{1-5}
        R53 vs BCL2 & & & 0.6216794 & 0.6829379\\ \cline{1-5}
        RR & & & 0.6528702 & 0.69094443\\\cline{1-5}
        R3 vs LHCGR & 0.6127419 & 0.6288637 & 0.7181227 & 0.6854638\\\cline{1-5}
        C & 0.8374688 & 0.8288982 & & \\ \cline{1-5}
        R & 0.8382382 & 0.85765386 & & \\ \cline{1-5}
        B2 & 0.8405463 & 0.80230945 & & \\ \cline{1-5}
        FX & 0.71343875 & 0.7239513 & & \\ \cline{1-5}
        F1 & 0.7648222 & 0.7616126 & 0.5658618 & 0.65824085\\ \cline{1-5}
        R & 0.8428854 & 0.8250908 & & \\ \cline{1-5}
      \endlastfoot
      \end{longtable}

答案1

  • 在您的表格代码片段中,您\endlastfoot在表格末尾有。正确的是\endfoot
  • 您定义了 6 列,但只使用了 5 列(第六列没有坏处,但是它的定义p{}是错误的,您需要指定此列的宽度,例如p{1em}
  • 由于您的表格中的第 2 - 5 列仅包含数字,因此我建议使用包S中定义的列类型siunitx
  • 相反,\cline{1-5}在表格宽度为 5 列时,您可以使用更简单/更短的\hline

    \documentclass{article}
    \usepackage{makecell,   % new, for \thead
                longtable}
    \renewcommand\theadfont{\small}
    \usepackage{siunitx}
    \begin{document}
        \begin{longtable}{|c|*{4}{S[table-format=1.8]|}}    % p{1pt}|
    \caption{caption}
    \label{Spearman and distance correlation}                                       \\
        \hline
    \thead{G} & {\thead{B)}} & {\thead{B}} & {\thead{S (Group C)}} & {\thead{D}}    \\
        \hline
    \endfirsthead
        \hline
    \multicolumn{5}{|c|}{ \tablename \ \thetable{} continued from previous page}    \\
        \hline
    \thead{G} & {\thead{B)}} & {\thead{B}} & {\thead{S (Group C)}} & {\thead{D}}    \\
        \hline
    \endhead
        \hline
    \multicolumn{5}{|c|}{continued on next page}                                    \\
        \hline
    \endfoot
        \hline
    \endlastfoot
    TR  &               &               & 0.64711267& 0.6899505     \\  \hline
    CGR & 0.6605117     & 0.67962766    &           &               \\  \hline
    C2  & 0.60588574    & 0.58207303    &           &               \\  \hline
    C1  & 0.7528371     & 0.75355834    & 0.8530607 & 0.82074517    \\  \hline
    C2  &               &               & 0.65749854& 0.63852245    \\  \hline
    CR  &               &               & 0.61507607& 0.63170303    \\  \hline
    IA1 & 0.56433934    & 0.5921317     &           &               \\  \hline
    IR  & 0.84881425    & 0.8601397     &           &               \\  \hline
    I   & 0.8097711     & 0.834002      &           &               \\  \hline
    HSD17B1 vs IGF1R
        & 0.68974805    & 0.7168968     &           &               \\  \hline
    HGR & 0.62358147    & 0.6271943     &           &               \\  \hline
    HX  &               &               & 0.61812353& 0.65268934    \\  \hline
    H3  &               &               & 0.8229002 & 0.8185904     \\  \hline
    R53 vs BCL2
        &               &               & 0.6216794 & 0.6829379     \\  \hline
    RR  &               &               & 0.6528702 & 0.69094443    \\  \hline
    R3 vs LHCGR
        & 0.6127419     & 0.6288637     & 0.7181227 & 0.6854638     \\  \hline
    C   & 0.8374688     & 0.8288982     &           &               \\ \hline
    R   & 0.8382382     & 0.85765386    &           &               \\ \hline
    B2  & 0.8405463     & 0.80230945    &           &               \\ \hline
    FX  & 0.71343875    & 0.7239513     &           &               \\ \hline
    F1  & 0.7648222     & 0.7616126     & 0.5658618 & 0.65824085    \\ \hline
    R   & 0.8428854     & 0.8250908     &           &               \\
    \end{longtable}
    \end{document}
    

在此处输入图片描述

相关内容