![编写算法时出现未定义的控制序列错误](https://linux22.com/image/442544/%E7%BC%96%E5%86%99%E7%AE%97%E6%B3%95%E6%97%B6%E5%87%BA%E7%8E%B0%E6%9C%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E6%8E%A7%E5%88%B6%E5%BA%8F%E5%88%97%E9%94%99%E8%AF%AF.png)
我正在尝试编写算法,但出现了如下错误
未定义的控制序列..
我的代码如下,谁能告诉我为什么会出现这个错误以及如何删除
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{algorithm}
\usepackage{algorithmic}
%package for multi affiliations
%\usepackage{authblk}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\begin{algorithm}[t]
\caption{\name\ Algorithm}
\label{alg:algo1}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE bbbbbbbbbbbbbbbbbbb
\ENSURE eeeeeeeeeeeee
\\ \textit{ttttttttttt}
\STATE gggggggggggggggggggggg
\\\textit{jjjjjjjjjjjjjjj}
\FOR{ $user$ \(i\in n\) in $p$}
\STATE wwwwwwwwwwwwwwwwwwwwwwww
\STATE dddddddddddddddd
\ENDFOR
\STATE tttttttttttttttt
\STATE vvvvvvvvvvvvvvvvvvvvvvv
\\ \textit{vvvvvvvvvvv}
\STATE vvvvvvvvvvvvvvvvvvv
\STATE vvvvvvvvvvvvvvvvvvvv
\\ \textit{bbbbbbbbbbbb}
\STATE bbbbbbbbbbbb
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
那么,产生的错误信息是
! Undefined control sequence.
<argument> \ignorespaces \name
\ Algorithm
这意味着命令\name
未定义。在代码的第 19 行中定义它或仅使用名称。更改
\caption{\name\ Algorithm} % <======================== undefined \name
到
\caption{name\ Algorithm} % <======================== undefined \name
以下 mwe 编译时没有错误:
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{algorithm}
\usepackage{algorithmic}
%package for multi affiliations
%\usepackage{authblk}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\begin{algorithm}[t]
\caption{\name\ Algorithm} % <======================== undefined \name
\label{alg:algo1}
\begin{algorithmic}[1]
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\REQUIRE bbbbbbbbbbbbbbbbbbb
\ENSURE eeeeeeeeeeeee
\\ \textit{ttttttttttt}
\STATE gggggggggggggggggggggg
\\\textit{jjjjjjjjjjjjjjj}
\FOR{ $user$ \(i\in n\) in $p$}
\STATE wwwwwwwwwwwwwwwwwwwwwwww
\STATE dddddddddddddddd
\ENDFOR
\STATE tttttttttttttttt
\STATE vvvvvvvvvvvvvvvvvvvvvvv
\\ \textit{vvvvvvvvvvv}
\STATE vvvvvvvvvvvvvvvvvvv
\STATE vvvvvvvvvvvvvvvvvvvv
\\ \textit{bbbbbbbbbbbb}
\STATE bbbbbbbbbbbb
\end{algorithmic}
\end{algorithm}
\end{document}