我在我的一个文档中使用了自定义浮动环境,如下所述这里。这曾经与 一起工作\documentclass{article}
,但是,当我更改为\documentclass{revtex4-2}
它给出了一个我无法理解的错误。实际上,这三个不同的错误都指向同一行(即自\end
定义浮动环境):
Missing \endcsname inserted.
<to be read again>
\c@float@type
l.24 \end{program}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
------------------------------------------------------------
Missing number, treated as zero.
<to be read again>
\endcsname
l.24 \end{program}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
------------------------------------------------------------
Extra \endcsname.
<recently read> \endcsname
l.24 \end{program}
I'm ignoring this, since I wasn't doing a \csname.
这是重现错误的示例脚本:
% \documentclass{article} % this works
\documentclass{revtex4-2} % this doesn't work
\usepackage[utf8]{inputenc}
\usepackage{float}
% From: https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Custom_floats
\floatstyle{ruled}
\newfloat{program}{hbt}{lop}
\floatname{program}{Program}
\begin{document}
\begin{program}
\begin{verbatim}
class HelloWorldApp {
public static void main(String[] args) {
//Display the string
System.out.println("Hello World!");
}
}
\end{verbatim}
\caption{The Hello World! program in Java.}
\end{program}
\end{document}
答案1
解决方案非常简单。根据auguide4-2.pdf
,所有自定义浮点数都应该在序言之外定义
这样它就不会再抛出任何错误
\documentclass{revtex4-2}
\usepackage[utf8]{inputenc}
\usepackage{float}
\begin{document}
\floatstyle{ruled}
\newfloat{program}{hbt}{lop}
\floatname{program}{Program}
\begin{program}
\begin{verbatim}
class HelloWorldApp {
public static void main(String[] args) {
//Display the string
System.out.println("Hello World!");
}
}
\end{verbatim}
\caption{The Hello World! program in Java.}
\end{program}
\end{document}