如何使用包“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会导致类revtex4和类的多个错误/警告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 结果如下:

结果表

相关内容