In the MWE, I try to add line continuation indent to the answer given in Properly indent comments with no line-numbering in algorithmicx
E.g. I am trying to write the \LineCommentCont
.
I am using the linegoal
package to set the width parameter of the \parbox
automatically, and \hangindent
to indent the continuation.
I have two problems: 1) \linegoal
seems to return a little less space than what is available. 2) How should I assign right \hangindent
amount?
Alternatively, you can supply an answer with a totally different approach.
\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{linegoal}
\makeatletter
\algnewcommand{\LineComment}[1]{\Statex \hskip\ALG@thistlm \(\triangleright\) #1}
\algnewcommand{\LineCommentCont}[1]{\Statex \hskip\ALG@thistlm \parbox[t]{\linegoal}{\hangindent=1em\hangafter=1 $\triangleright$ #1}}
\makeatother
\begin{document}
\begin{algorithm}[!ht]
\caption{My Algo.}\label{myalgo}
\begin{algorithmic}[1]
\State $\epsilon$ = 1.0; \Comment{Explore Latency Dimension}
\While {explorationTime $\leq$ timeLimit}
\State $\epsilon = \epsilon / 2$;
\State calculateIncrements($\epsilon$);
\LineComment{Explore L dimension}
\While {lQuery $\leq$ lUpperLimit}
\State Query (0, Query, bQuery, pQuery);
\If {result = WORKING}
\State mark points
\LineComment{no need to explore more. we just want to stop over here. no need to explore more. we just want to stop over here. no need to explore more. we just want to stop over here. }
\LineCommentCont{no need to explore more. we just want to stop over here. no to explore more. we just want to stop over here. 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}
\end{document}
Best Answer
Use the following definition of
\LineCommentCont
:Since you're indenting the "list" (algorithm) by
\ALG@thistlm
you only need to subtract that from\linewidth
in order to have the correct width of you\parbox
. There is therefore no need to uselinegoal
to determine the remaining width of the line.The width
\trianglerightwidth
is obtained by measuring the width of$\trianglewidth$~
.I've added some
\strut
s to the macros to avoid line height problems when you don't have descenders in your comment.The indentation at every level is incremented by
\algorithmicindent
(default is1.5em
). Usinginserts an equivalently-spaced indentation to what you see with the other constructions: