LaTeX 錯誤:\begin{document} 以 \end{section} 結尾

LaTeX 錯誤:\begin{document} 以 \end{section} 結尾

我遇到了上述錯誤訊息。這是我到目前為止所擁有的:

\documentclass{article}
\title{Assignment \#1}
\author{First Name Last Name}
\date{March 20, 2014}

\begin{document}
\maketitle     
\section*{Question 1}
\textit{Scenario containing 2 pirates :} \\*\\*
Regardless of how the gold is split, the 2nd pirate will vote against the 1st pirate and take all the gold. \\*\\*
\end{section}

\textit{Scenario containing 3 pirates:} 

\begin{table}[ht]
\caption{3 Pirates}
\centering
\begin{tabular}{c c c}
\hline\hline
Pirate\#1 & Pirate\#2 & Pirate\#3 \\  
\hline
x & x &  x \\
\hline
\end{tabular}
\end{table}


\end{document}

答案1

LaTeX 提供了兩種執行內容的形式:巨集和環境。哪個更可取取決於用途。哪些可用通常超出您的控制範圍。有些命令以兩種形式給出,例如\centering相對\begin{center}...\end{center}

但關鍵的用法差異在於,巨集的參數(如果有)是在呼叫時提供的,而環境則被告知以語句開始\begin{environment-name},並在該環境設定的控制下繼續運行,直到\end{environment-name}調用 an 為止。在這方面,環境需要\begin{}...\end{}「書立」的對稱性。

在您的範例中,\section是宏,而不是環境。也就是說,它不是以 開始的\begin{section}。當呼叫時,它會產生一個標題來顯示該節的標題,它會為該節建立一個編號,並且可能會記下目錄的條目。節標題可以用更大、更粗的字體或任何多種方式進行樣式化,具體取決於\section類別和/或包含的套件的定義方式。但是,一旦處理了參數\section,後續文字就不在「節環境」的範圍內,而只是常規文件文字。 \section與此無關。

因此,\end{section}您的 MWE 中出現的 是不正確的。刪除該行程式碼即可編譯。

相關內容