原 文:Misplaced \noalign
譯 者:Xovee
翻譯時間:2020年6月14日
Misplaced \noalign
當你錯誤地使用了 \hline 命令,就會遇到這個錯誤。
出錯原因
在表格外使用 \hline
\hline 命令只可以在表格環境 tabular 之中使用。你不可以使用這個命令來在文檔的其他地方創建水平線,例如下面這個例子:
%In your preamble
\title{On the General Molecular Theory of Heat}
\author{A. Einstein}
% In the body of your document
\maketitle
\hline
這將會拋出一個錯誤:
當你想在表格之外插入水平線時,你可以使用 \hrule 命令。
在表格中錯誤地使用了 \hline
當你在表格之中使用 \hline 命令時,除過表格的第一行,在其他行中,命令之前必須添加 \\
。例如:
\begin{tabular}{|l|l|} \hline
First Name: & Albert \\ \hline
Second Name: & Einstein \hline
\end{tabular}
這個例子中,第一個 \hline 是正確的。對於最後一個 \hline ,它之前沒有 \\
。正確的做法應該是:
\begin{tabular}{|l|l|} \hline
First Name: & Albert \\ \hline
Second Name: & Einstein \\ \hline
\end{tabular}