遇到該問題的根本原因是編譯器認為表格沒有正確換行(末尾沒有添加”\“)。但是,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}