我的长表代码有什么问题?

我的长表代码有什么问题?

我从 excel2latex 工具中获取了表格的代码,然后我注意到我需要\longtable包。将 longtable 添加到表环境后,我的代码出现错误:

\begin{landscape} 
\begin{longtable}{|l|l|l|l|l|l|l|}
  \centering
  \caption{Add caption}
    \toprule
    \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{B} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{A} \\
    \midrule
    \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} \\
          &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{\multirow{8}[0]{*}{77 K}} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & TS : 1 minute &       &       & TS : 1 minute \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{Adsorption} & P: 28 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       &       & TS : 30 minute \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{\multirow{12}[0]{*}{87 K}} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Adsorption} & P: 32 bar &       & \multicolumn{1}{l}{} & TS: 1 minute \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar &       & \multicolumn{1}{l}{Adsorption} & P: 28 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       & \multicolumn{1}{l}{} &  \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & TS: 40 minute &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{} & TS: 20 minute \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{Adsorption} & P: 28 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{} &  \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} &       &       & \multicolumn{1}{l}{} & TS: 40 minute \\
          &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{\multirow{8}[0]{*}{97 K}} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       & \multicolumn{1}{l}{Desorption} & DP: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & TS: 1 minute &       & \multicolumn{1}{l}{} & TS: 1 minute \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar &       &       &  \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar &       &       &  \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       &       &  \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & TS: 13 minute &       &       &  \\
          &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{\multirow{4}[0]{*}{112 K}} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & $\Delta$P: 8 bar -> 10 > $\mathrm{P_{eq}}$ > 25 bar &       & \multicolumn{1}{l}{} & DP: 8 bar -> 10 > Peq > 25 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & TS: 1 minute &       & \multicolumn{1}{l}{} & TS: 1 minute \\
          &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{\multirow{4}[0]{*}{127 K}} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{} & TS: 1 minute &       & \multicolumn{1}{l}{} & TS: 1 minute \\
          &       & \multicolumn{1}{l}{} &       &       &       &  \\
    \multicolumn{1}{c}{\multirow{2}[0]{*}{RT}} &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 6 bar -> 0 > $\mathrm{P_{eq}}$ > 25 bar &       & \multicolumn{1}{l}{Adsorption} & $\Delta$P: 4 bar -> 0 > $\mathrm{P_{eq}}$ > 25 bar \\
    \multicolumn{1}{c}{} &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar &       & \multicolumn{1}{l}{Desorption} & $\Delta$P: 10 bar \\
          &       &       & Ts: 120 minutes &       &       & Ts: 120 minutes \\
    \bottomrule
  \label{tab:meacon}%
\end{longtable}%
\end{landscape}

我尝试编译代码后收到的错误;

> LaTeX Warning: Reference `tab:meacon' on page 58 undefined on input
> line 178.
> 
> [58] ! Misplaced \noalign. \caption ->\noalign 
>                     \bgroup \@ifnextchar [{\egroup \LT@c@ption \@firstofone ... l.184   \caption
>                 {Add caption} ? 
> 
> Process has been terminated ...

我该怎么做才能创建这样的表?

答案1

首先,该\centering命令在环境中不起作用longtable,它被可选参数替换[c],如\begin{longtable}[c]{format}

其次,您需要以 来结束该\caption\\

假设您正在使用该multirow命令,您应该\\*在相应(子)行的末尾发出命令,以便这些块不会跨页面分割。

如果愿意,您可以向行尾标记添加可选间距参数,而不是插入空白行。例如\\[1ex]\\*[1ex]

您的垂直规则似乎放置不一致,只需将其删除即可。这样就不需要使用大多数\multicolumn命令了。

\endhead在您希望在后续页面上重复的行之后添加。

<您的表格包含必须放入数学模式的材料。带单位的数字最好通过siuntx包打印。

这是您表格中的大部分内容,其中第一个块重复多次。我没有在行间添加额外的空格。

部分输出示例

\documentclass{article}

\usepackage{longtable,multirow,lscape,booktabs,siunitx}

\begin{document}
\begin{landscape} 
\begin{longtable}[c]{lllllll}
  \caption{Add caption}\\
    \toprule
    & & & \multicolumn{1}{c}{B} & & & \multicolumn{1}{c}{A} \\
    \midrule
    \endhead
    \multirow{8}[0]{*}{77 K}
    & & Adsorption & $\Delta\mathrm P$: $\SI{4}{bar} \to 0 > \mathrm{P_{eq}}
    > \SI{10}{bar}$ &    & Adsorption & $\Delta\mathrm P: \SI{4}{bar} \to 0 >
    \mathrm{P_{eq}} > \SI{10}{bar}$ \\* 
    & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 > \mathrm{P_{eq}} >
    \SI{25}{bar}$ & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 >
    \mathrm{P_{eq}} > \SI{25}{bar}$ \\*
    & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} & & Desorption &
    $\Delta\mathrm P$: \SI{10}{bar} \\*  
    & & & TS: \SI{1}{minute} & & & TS: \SI{1}{minute} \\*
    & & & & & Adsorption & $\mathrm P$: \SI{28}{bar} \\*
    & & & & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} \\*
    & & & & & & TS: \SI{30}{minute} \\
    \midrule
    \multirow{8}[0]{*}{77 K}
    & & Adsorption & $\Delta\mathrm P$: $\SI{4}{bar} \to 0 > \mathrm{P_{eq}}
    > \SI{10}{bar}$ &    & Adsorption & $\Delta\mathrm P: \SI{4}{bar} \to 0 >
    \mathrm{P_{eq}} > \SI{10}{bar}$ \\* 
    & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 > \mathrm{P_{eq}} >
    \SI{25}{bar}$ & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 >
    \mathrm{P_{eq}} > \SI{25}{bar}$ \\*
    & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} & & Desorption &
    $\Delta\mathrm P$: \SI{10}{bar} \\*  
    & & & TS: \SI{1}{minute} & & & TS: \SI{1}{minute} \\*
    & & & & & Adsorption & $\mathrm P$: \SI{28}{bar} \\*
    & & & & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} \\*
    & & & & & & TS: \SI{30}{minute} \\
    \midrule
    \multirow{8}[0]{*}{77 K}
    & & Adsorption & $\Delta\mathrm P$: $\SI{4}{bar} \to 0 > \mathrm{P_{eq}}
    > \SI{10}{bar}$ &    & Adsorption & $\Delta\mathrm P: \SI{4}{bar} \to 0 >
    \mathrm{P_{eq}} > \SI{10}{bar}$ \\* 
    & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 > \mathrm{P_{eq}} >
    \SI{25}{bar}$ & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 >
    \mathrm{P_{eq}} > \SI{25}{bar}$ \\*
    & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} & & Desorption &
    $\Delta\mathrm P$: \SI{10}{bar} \\*  
    & & & TS: \SI{1}{minute} & & & TS: \SI{1}{minute} \\*
    & & & & & Adsorption & $\mathrm P$: \SI{28}{bar} \\*
    & & & & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} \\*
    & & & & & & TS: \SI{30}{minute} \\
    \midrule
    \multirow{8}[0]{*}{77 K}
    & & Adsorption & $\Delta\mathrm P$: $\SI{4}{bar} \to 0 > \mathrm{P_{eq}}
    > \SI{10}{bar}$ &    & Adsorption & $\Delta\mathrm P: \SI{4}{bar} \to 0 >
    \mathrm{P_{eq}} > \SI{10}{bar}$ \\* 
    & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 > \mathrm{P_{eq}} >
    \SI{25}{bar}$ & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 >
    \mathrm{P_{eq}} > \SI{25}{bar}$ \\*
    & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} & & Desorption &
    $\Delta\mathrm P$: \SI{10}{bar} \\*  
    & & & TS: \SI{1}{minute} & & & TS: \SI{1}{minute} \\*
    & & & & & Adsorption & $\mathrm P$: \SI{28}{bar} \\*
    & & & & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} \\*
    & & & & & & TS: \SI{30}{minute} \\
    \midrule
    \multirow{8}[0]{*}{77 K}
    & & Adsorption & $\Delta\mathrm P$: $\SI{4}{bar} \to 0 > \mathrm{P_{eq}}
    > \SI{10}{bar}$ &    & Adsorption & $\Delta\mathrm P: \SI{4}{bar} \to 0 >
    \mathrm{P_{eq}} > \SI{10}{bar}$ \\* 
    & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 > \mathrm{P_{eq}} >
    \SI{25}{bar}$ & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 >
    \mathrm{P_{eq}} > \SI{25}{bar}$ \\*
    & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} & & Desorption &
    $\Delta\mathrm P$: \SI{10}{bar} \\*  
    & & & TS: \SI{1}{minute} & & & TS: \SI{1}{minute} \\*
    & & & & & Adsorption & $\mathrm P$: \SI{28}{bar} \\*
    & & & & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} \\*
    & & & & & & TS: \SI{30}{minute} \\
    \midrule
    \multirow{8}[0]{*}{77 K}
    & & Adsorption & $\Delta\mathrm P$: $\SI{4}{bar} \to 0 > \mathrm{P_{eq}}
    > \SI{10}{bar}$ &    & Adsorption & $\Delta\mathrm P: \SI{4}{bar} \to 0 >
    \mathrm{P_{eq}} > \SI{10}{bar}$ \\* 
    & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 > \mathrm{P_{eq}} >
    \SI{25}{bar}$ & & & $\Delta\mathrm P$: $\SI{8}{bar} \to 10 >
    \mathrm{P_{eq}} > \SI{25}{bar}$ \\*
    & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} & & Desorption &
    $\Delta\mathrm P$: \SI{10}{bar} \\*  
    & & & TS: \SI{1}{minute} & & & TS: \SI{1}{minute} \\*
    & & & & & Adsorption & $\mathrm P$: \SI{28}{bar} \\*
    & & & & & Desorption & $\Delta\mathrm P$: \SI{10}{bar} \\*
    & & & & & & TS: \SI{30}{minute} \\
    \bottomrule
  \label{tab:meacon}
\end{longtable}
\end{landscape}
\end{document}

相关内容