1

I am writing a pseudocode/algorithm in my latex Overleaf document. I had a problem that my algorithm was too long so I had to split it into multiple "blocks". However, now I can't add comments normally; writing \Comment{comment here} simply writes {Comment here}.

Example:

\usepackage{algorithm,algpseudocode,algcompatible}

\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}


\begin{algorithm}                     
\caption{y}          
\label{algoritmi}                          
\begin{algorithmic} [1]                   
\REQUIRE   $x_0$
\ENSURE     $y$
\STATE $x=x_0$ \Comment{Comment here}
\algstore{myalg}
\end{algorithmic}
\end{algorithm}
Normal text
\begin{algorithm}                     
\begin{algorithmic} [1]                  
\algrestore{myalg}
\STATE $x = x_0$
\STATE $y = x$
\end{algorithmic}
\end{algorithm}

And it looks like: [![enter image description here](https://i.sstatic.net/xcx1a.png)](https://i.sstatic.net/xcx1a.png)

How can I fix the comment? I would like it to read e.g. ▹ Comment here.

1 Answer 1

2

I wouldn't mix algpseudocode and algcompatible. Since you want algpseudocode style comments, just use the former.

\documentclass{article}
\usepackage{algorithm,algpseudocode}
\usepackage{caption}

\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}

\begin{document}

\begin{algorithm}
\caption{y}
\label{algoritmi}

\begin{algorithmic}[1]
\Require \strut $x_0$
\Ensure $y$
\State $x=x_0$ \Comment{Comment here}
\algstore{myalg}
\end{algorithmic}

\end{algorithm}

Normal text

\begin{algorithm}
\addtocounter{algorithm}{-1}
\caption{y (continued)}
\begin{algorithmic}[1]
\algrestore{myalg}
\State\strut $x = x_0$
\State $y = x$
\end{algorithmic}
\end{algorithm}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .