LaTeX 表格排版中遇到 Misplaced \noalign


遇到该问题的根本原因是编译器认为表格没有正确换行(末尾没有添加”\“)。但是,LaTeX 认为没有正确换行不代表真的没有正确换行。当表格使用了复杂的插入方式时,例如循环,LaTeX 无法正确判断。

报错示范

\begin{table}
  \begin{tabular}{lrrrrr}
    p & cluster distance & SE & gene & gene/SE
    \DTLforeach*{at_counts}
    {
    \pvalue=p value,
    \cd=cluster distance,
    \seCount=SE count,
    \geneCount=gene count,
    \ratio=ratio,
    \tored=tored
    }
    {
    \tabularnewline
    \ifthenelse{\tored=1}
    {
    \rowcolor{green} \pvalue & \cd & \seCount & \geneCount & \ratio
    }
    {
    \pvalue & \cd & \seCount & \geneCount & \ratio
    }
    }
  \end{tabular}
\end{table}

在上面的例子当中,使用了 datatool 宏包来导入 csv 表格数据,使用 colortbl 宏包来修改表格底色。如果忽略错误,结果符合预期。但是由于\tabularnewline没有直接和\rowcolor相邻,所以会报错。进行以下修改后不会报错,同时结果符合预期。

\begin{table}
  \begin{tabular}{lrrrrr}
    p & cluster distance & SE & gene & gene/SE
    \DTLforeach*{at_counts}
    {
    \pvalue=p value,
    \cd=cluster distance,
    \seCount=SE count,
    \geneCount=gene count,
    \ratio=ratio,
    \tored=tored
    }
    {
    \ifthenelse{\tored=1}
    {
    \tabularnewline
    \rowcolor{green} \pvalue & \cd & \seCount & \geneCount & \ratio
    }
    {
    \tabularnewline
    \pvalue & \cd & \seCount & \geneCount & \ratio
    }
    }
  \end{tabular}
\end{table}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM