Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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