2

I have the following code that generated error

! LaTeX Error: Something's wrong--perhaps a missing \item.
l.193     \STATE
             \label{alg:line3}Sort NGs in CDR in ascending order based o...

\usepackage[noend]{algorithmic}
\usepackage{algorithm}
{\scriptsize
\begin{algorithm}
\caption{An Algorithm}
\label{alg1}
\begin{algorithmic}[1]
\REQUIRE a set of candidate data records $CDRs$
\ENSURE a set of re-segmented data records $DRs$
\STATE \label{alg:line1}Sort CDRs in ascending order based on their vertical positions
\FOR\label{alg:line2}{each CDR $\in$ CDRs}
    %the error happened at the following line 
    \STATE \label{alg:line3}Sort NGs in CDR in ascending order based on their vertical positions
%some other code
}

so I am wondering how to solve the issue.

cheers

2

You have the wrong syntax in the \FOR line:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}

\begin{algorithm}
\caption{An Algorithm}
\label{alg1}
\begin{algorithmic}[1]
\REQUIRE a set of candidate data records $CDRs$
\ENSURE a set of re-segmented data records $DRs$
\STATE \label{alg:line1}Sort CDRs in ascending order based on their vertical positions
\FOR{each CDR $\in$ CDRs}\label{alg:line2}
    \STATE \label{alg:line3}Sort NGs in CDR in ascending order based on their vertical positions
\ENDFOR
\end{algorithmic}
\end{algorithm}

Reference to FOR: \ref{alg:line2}

Reference to first STATE: \ref{alg:line1}

Reference to second STATE: \ref{alg:line3}

\end{document}

The argument to \FOR must follow immediately the command, the \label should go after it.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.