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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In an algorithm using the algorithmic package, I would like to display for some lines a special symbol (e.g. a +), instead of their line number. Is this possible?

Edit: Here's a minimal working example.

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}

\begin{algorithm}[tb]
  \caption{My algorithm}
\begin{algorithmic}[1]
  \STATE{foo}
  \STATE{bar}
\end{algorithmic}
\end{algorithm}

\end{document}
share|improve this question
    
Have you found a solution to your problem? – Mark Heckmann Aug 10 '14 at 13:39
    
@MarkHeckmann Unfortunately, I have not. – 3lectrologos Aug 10 '14 at 19:07
    
@MarkHeckmann I posted an answer yesterday. Does it work for you? – jarauh Dec 2 '15 at 11:43
up vote 2 down vote accepted

The following seems to work:

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmic}

\makeatletter
\newcommand{\plusline}{%
  \let\old@ALC@lno=\ALC@lno%
  \renewcommand{\ALC@lno} {+%
    \global\let\ALC@lno=\old@ALC@lno}%
}
\makeatother

\begin{document}

\begin{algorithm}[tb]
  \caption{My algorithm}
\begin{algorithmic}[1]
  \STATE{foo}
  \STATE{bar}
  \plusline
  \STATE{foo}
  \STATE{bar}
  \STATE{foo}
  \STATE{bar}
  \STATE{foo}
  \STATE{bar}
\end{algorithmic}
\end{algorithm}

\end{document}

In algorithmic.sty, the command \ALC@lno is responsible to print the line number. The above code changes the command temporarily to just output + and then to reset itself.

output

share|improve this answer

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.