5
$\begingroup$
a=4;          (*length*)
b=5;          (*width*)
s=a*b;        (*area*)

Is there any way to align the code above left and also align the comments? Now it looks good because I add some space before (**). However, when I change the code, such as below, I need to add or delete some space. This is not what I want.

a=400;          (*length*)
b=50;          (*width*)
p=a*b+a+b;        (*coment*)

There is a function called \[AlignmentMarker]. It only alines the comments, but not the code:

a=400;          \[AlignmentMarker](*length*)
b=5;          \[AlignmentMarker](*width*)
s=a*b+a+b;        \[AlignmentMarker](*area*)

enter image description here

Is there any better way?

$\endgroup$
  • $\begingroup$ one option would be to use code cell instead on input cell. Then you can align things manually as you want without having the notebook automatic formatting be involved. $\endgroup$ – Nasser Jan 15 '19 at 3:52
  • $\begingroup$ How general it should be? Do you want to automatically allign them for readability or to have them aligned 'live' as you type? What if the code is longer than the page or window width, etc etc. $\endgroup$ – Kuba Jan 15 '19 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.