Is it possible in algorithmicx
package to have comments not aligned to the right side?
For example I have code like this –
\begin{algorithm}[!ht]
\caption{My Algo.}
\label{myalgo}
\begin{algorithmic}
\State $\epsilon$ = 1.0;
\Comment{Explore Latency Dimension}
\While {explorationTime <= timeLimit}
\State $\epsilon$ = $\epsilon$ / 2;
\State calculateIncrements($\epsilon$);
\Comment{Explore L dimension}
\While {lQuery <= lUpperLimit}
\State Query (0, Query, bQuery, pQuery);
\If {result = WORKING}
\State mark points
\Comment{no need to explore more. we just want to stop over here.}
\State Break
\Else
\If {result = NOT WORKING}
\State mark from 0 to lQuery as NOT WORKING.
\EndIf
\EndIf
\State lQuery += lEpsIncr;
\EndWhile
\EndWhile
\State $calcPoints()$
\end{algorithmic}
\end{algorithm}
So what is happening is that, the package everytime aligns the comments to the right side. But for this comment \Comment{no need to explore more. we just want to stop over here.}
, I would like it to have it on single line rather than multiple lines and aligned to right. It becomes a little confusing for me.
Is it possible that we can have comments like –
> no need to explore more. we just want to stop over here.
Break
It should be aligned at the indentation level of the statements.
Best Answer
Modifying the comment macro is possible using
\algrenewcomment
, likeThe original
\Comment
command inserted an\hfill
, which I've removed above. This would replace the existing\Comment
command globally. However, you can also define your own (new)\LineComment
command,and intermix it with the regular
\Comment
, like I did below: