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