未定义控制序列\State \COMMENT
。
手册明确指出我可以使用\comment
。我使用\usepackage{algpseudocode} \usepackage{algorithm}
。这是我的代码:
\documentclass[10pt, a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath,graphicx,subfigure}
\title{{Bachelor Thesis\\[0.5em]}
{\bf \huge Road Inventory\\Detection and Recognition\\[0.5em]}
{\bf Weekly Report 3}}
\author{Poul Sørensen. s093294}
%\setlength{\parindent}{0mm}
\setlength{\parskip}{1.5mm}
\usepackage{lettrine}
\usepackage[draft,english]{fixme} %Pakke til at skrive marginnoter under arbejdet. Skift draft til final når der skal printes. Brug 'fxnote{}','fxwarning', 'fxerror' eller 'fxfatal' alt efter behov.
%\fxsetup{layout=margin} %Footnote anbefales som option - men er ikke specielt praktisk?
\newcommand{\openCV}{\texttt{OpenCV}~}
\newcommand{\cpp}{\texttt{C++}~}
\usepackage{url}
% Different font in captions
\usepackage[font=small,format=plain,labelfont=bf,up,textfont=it,up,margin=7mm]{caption}
\usepackage{multirow}
\usepackage{array}
\usepackage{rotating}
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\renewcommand{\floatpagefraction}{0.75}
\usepackage{color}
\definecolor{quotationcolour}{rgb}{0.95,0.95,0.95}
\definecolor{quotationmarkcolour}{rgb}{0,0.4,0.9}
% Double-line for start and end of epigraph.
\newcommand{\epiline}{\hrule \vskip -.2em \hrule}
% Massively humongous opening quotation mark.
\newcommand{\hugequote}{%
\fontsize{42}{48}\selectfont \color{quotationmarkcolour} \textbf{``}
\vskip -.5em
}
\newcounter{quotecounter}
% Beautify quotations.
\newcommand{\epigraph}[2]{%
\refstepcounter{quotecounter}
\begin{flushright}
\colorbox{quotationcolour}{%
\parbox{.95\textwidth}{%
\epiline \vskip 1em {\hugequote} \vskip -.5em
\parindent 2.2em
#1\begin{flushright}\textbf{Quote \thesection.\thequotecounter}~~ \textsc{#2}\end{flushright}
\epiline
}
}
\end{flushright}
}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{eqparbox}
%\usepackage{program}
%\renewcommand{\algorithmiccomment}[1]{\hfill\eqparbox{COMMENT}{\backslash\backslash #1}}
\begin{document}
\maketitle
\newpage
\section{Performance Measurement }
There exist a few methods for measure performance~\cite{Book:OpenCV}. First one of interest is \textit{cross-validation} and its close related technique of \textit{bootstrapping}. A great outline on the topic can be found online\footnote{www.faqs.org/fags/ai-fag/neural-nets/part3/section-12.html}.
Cross-validation involves splitting the data $\Phi $ into $k$ distinct subsets ${\Phi_1,\cdots,\Phi_{k-1},\Phi_k}$, training $k$ times on $k-1$ of the subsets and testing with left out set. The $k$ test results can then be averaged to a final score.
%\begin{algorithm}
\begin{algorithmic}
\Procedure{CrossValidate}{$\Phi$}
\ForAll{$\phi \in {\Phi_1,\cdots,\Phi_{k-1},\Phi_k}$}
\State $model =$ Train($\Phi \setminus \phi$ )
\ForAll{$s \in \phi$ }
\State \COMMENT{hej}
\EndFor
\EndFor
\EndProcedure
\end{algorithmic}
%\end{algorithm}
\section{Related Work}\fxnote{(intended for report.)}
\subsection{Machine Learning}
\input{../../"Report Parts"/MachineLearning/ML.tex}
\subsubsection{Prediction Trees}
\input{../../"Report Parts"/MachineLearning/PredictionTrees.tex}
\subsection{Colour Analysis}
\subsection{Decision Tree}
\subsection{Forest of Decision Trees}
\subsection{Hough Forest}
\newpage
\section*{Project status according to the study plan}
All under control. Report work is doing well.
\bibliographystyle{plain}
\bibliography{../../../../references}
\appendix
\end{document}
答案1
LaTeX 在控制序列方面区分大小写。因此,\Comment
不同于\COMMENT
,\comment
以及所有其他有效组合。这就是您在显示注释时所追求的 - 使用\Comment{...}
:
\documentclass{article}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithmic}
\Procedure{CrossValidate}{$\Phi$}
\ForAll{$\phi \in {\Phi_1,\cdots,\Phi_{k-1},\Phi_k}$}
\State $model =$ Train($\Phi \setminus \phi$ )
\ForAll{$s \in \phi$ }
\State \Comment{hej}
\EndFor
\EndFor
\EndProcedure
\end{algorithmic}
\end{document}
来自algorithmicx
文档(部分2.4 在来源中添加注释,第 4 页):
可以使用宏将注释放置在源代码的任何地方
\Comment
...
答案2
我想补充一点,这也是有帮助的。有时你需要指定评论的位置。所以在文档的顶部
\newcommand{\Comment}[1]{{\hskip3em$\rightarrow$ #1}}
在算法内部你可以轻松使用
\Comment
结果将如下所示
x → Here is a comment