3

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}
  • 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
2

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

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.