Take the 2-minute tour ×
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.

Writing comments in pseudocode, I wanted to insert comments which are not aligned to the right side of the line which is commented. This thread helped me a lot.

However, I want comments to stand above the code line to which they refer and be always left-aligned.

Reason: If the comment refers to an elsif, then the comment is inside the previous if-block. Thus, it is indented. I don't want it to be indented, I want it to be at the same horizontal position as the corresponding line is.

Starting with this

\algnewcommand{\LineComment}[1]{\State \(\triangleright\) #1}

How can I design it to be aligned corresponding to the next line (which is left-aligned in 90% of the cases)?

I am using this:

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}\parindent0mm
\algnewcommand{\LineComment}[1]{\State \(\triangleright\) #1}

Also, I want to define a new command, not redefine an existing one.

Thanks!

share|improve this question

1 Answer 1

try inserting \hfill

\algnewcommand{\LineComment}[1]{\State  \(\triangleright\) #1 \hfill~}
share|improve this answer
    
This keeps the triangle where it is and moves the actual comment to the right end of the line.. –  bogus Jan 23 '13 at 7:51
    
I just noticed that the problem description is not quite accurate: My comments are supposed to be left aligned, sorry. I updated the description –  bogus Jan 23 '13 at 7:52
    
put the \hfill before the triangle, then the \State should be left and the comment right aligned. See my edit –  Herbert Jan 23 '13 at 8:13
    
this pushes the comment to the right, not to the left –  bogus Jan 23 '13 at 8:37
    
see edit, but I need a complete example to see what you resally want –  Herbert Jan 23 '13 at 8:50

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.