如何使用套件“caption”和文檔類別“revtex4”解決錯誤“longtable*已定義”?

如何使用套件“caption”和文檔類別“revtex4”解決錯誤“longtable*已定義”?

我在編譯以下程式碼時遇到嚴重問題:

\documentclass[a4paper,reprint,aps,unsortedaddress]{revtex4}
\usepackage{longtable}
\usepackage{caption}


\begin{document}

\captionof{table}{This is a very nice table}
\begin{longtable}{c|c|c|c}
A & B & A & B \\ \hline
\end{longtable}
\addtocounter{table}{-1}

\captionof{table}{This is a very nice table}
\begin{longtable}{c|c|c|c}
A & B & A & B \\ \hline
\end{longtable}

\end{document}

錯誤訊息是

! LaTeX Error: Command \longtable* already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

您能幫我解決這個錯誤嗎?

答案1

好吧,您的程式碼中有三個問題:

  1. 類別revtex4已過時,當前類別是revtex4-2.你能改變嗎?
  2. 載入套件caption會導致 classrevtex4和 class出現多個錯誤/警告revtex4-2。只是不要加載它!
  3. \captionof{table}{This is a very nice table}caption僅當載入套件時才可能,但longtable定義了自己的標題\caption{This is a very nice table}\\(請參閱結束語\\!)

用下面的程式碼

\documentclass[a4paper,reprint,aps,unsortedaddress]{revtex4}

\usepackage{longtable}
%\usepackage{caption}


\begin{document}

\begin{longtable}{c|c|c|c}
\caption{This is a very nice table}\\
A & B & A & B \\ \hline
\end{longtable}


\addtocounter{table}{-1}
\begin{longtable}{c|c|c|c}
\caption{This is a very nice table}\\
A & B & A & B \\ \hline
\end{longtable}

\end{document}

我可以毫無錯誤地編譯類別revtex4revtex4-2 結果:

結果表

相關內容