![Latex 错误“命令 \AND 已经定义。\REQUIRE”与 ifacconf 文档类](https://linux22.com/image/413197/Latex%20%E9%94%99%E8%AF%AF%E2%80%9C%E5%91%BD%E4%BB%A4%20%5CAND%20%E5%B7%B2%E7%BB%8F%E5%AE%9A%E4%B9%89%E3%80%82%5CREQUIRE%E2%80%9D%E4%B8%8E%20ifacconf%20%E6%96%87%E6%A1%A3%E7%B1%BB.png)
我在 ifacconf 文档类中使用算法时,一直收到以下错误“命令 \AND 已定义。\REQUIRE”。我无法找出原因。示例代码如下:
\documentclass{ifacconf}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{graphicx} % include this line if your document contains figures
\usepackage{natbib} % required for bibliography
%===============================================================================
\usepackage{array}
\usepackage{algorithm}
\usepackage{algorithmic}
\floatname{algorithm}{Algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand{\algorithmicendif}{\textbf{end}}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.1cm}}% for convenience you can also define a new column type
\begin{document}
\begin{frontmatter}
\title{Test\thanksref{footnoteinfo}}
% Title, preferably not more than 10 words.
\thanks[footnoteinfo]{Test.}
\author[First]{Test}
\address[First]{Department of Electrical Engineering, Qatar University, Doha, Qatar (e-mail: [email protected], [email protected]).}
\begin{abstract} % Abstract of not more than 250 words.
test
\end{abstract}
\begin{keyword}
test
\end{keyword}
\end{frontmatter}
%===============================================================================
\maketitle
\thispagestyle{plain}
\pagestyle{plain}
\section{test}
\iffalse
\begin{algorithm}
\small
\caption{Caption.}
\label{alg1}
\begin{algorithmic}
\REQUIRE {$L$ - level, $L_{\textrm{max}}$ - Maximum level}
\ENSURE {$P_{\textrm{main}}$ - Main status}
\IF{$L \leq L_{\textrm{min}}$} \STATE {$P_{\textrm{main}}$ is ON}
\ELSIF{$L \geq L_{\textrm{max}}$} \STATE {$P_{\textrm{main}}$ is OFF}
\ELSE \STATE {$P_{\textrm{main}}$ status does not change}
\ENDIF
\end{algorithmic}
\end{algorithm}
% in the appendices.
\end{document}
答案1
不幸的是,该类定义\AND
代表 &(周围有空格)用于作者块。
您仍然可以加载algorithmic
,但需要做一些扭曲。
\documentclass{ifacconf}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{graphicx} % include this line if your document contains figures
\usepackage{natbib} % required for bibliography
%===============================================================================
\usepackage{array}
\usepackage{algorithm}
\usepackage{etoolbox}
% save the meaning of \AND and undefine it to keep algorithmic happy
\let\classAND\AND
\let\AND\relax
% load algorithmic
\usepackage{algorithmic}
% save the new meaning of \AND and restore the one of the class
\let\algoAND\AND
\let\AND\classAND
% but when we start \begin{algorithmic} we want its own \AND
\AtBeginEnvironment{algorithmic}{\let\AND\algoAND}
\floatname{algorithm}{Algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand{\algorithmicendif}{\textbf{end}}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.1cm}}% for convenience you can also define a new column type
\begin{document}
\begin{frontmatter}
\title{Test\thanksref{footnoteinfo}}
% Title, preferably not more than 10 words.
\thanks[footnoteinfo]{Test.}
\author[First]{Test}
\address[First]{Department of Electrical Engineering, Qatar University, Doha, Qatar (e-mail: [email protected], [email protected]).}
\begin{abstract} % Abstract of not more than 250 words.
test
\end{abstract}
\begin{keyword}
test
\end{keyword}
\end{frontmatter}
%===============================================================================
\maketitle
\thispagestyle{plain}
\pagestyle{plain}
\section{test}
\begin{algorithm}
\small
\caption{Caption.}
\label{alg1}
\begin{algorithmic}
\REQUIRE {$L$ - level, $L_{\textrm{max}}$ - Maximum level}
\ENSURE {$P_{\textrm{main}}$ - Main status}
\IF{$L \leq L_{\textrm{min}}$} \STATE {$P_{\textrm{main}}$ is ON}
\ELSIF{$L \geq L_{\textrm{max}}$} \STATE {$P_{\textrm{main}}$ is OFF}
\ELSE \STATE {$P_{\textrm{main}}$ status does not change}
\ENDIF
\end{algorithmic}
\end{algorithm}
% in the appendices.
\end{document}
我相信你们都\textrm
应该如此\mathrm
。