I do not know if this was asked before or not. Simple formating issue. I noticed it is sometimes hard to align comments (----) on top of each others. Must be a font type issue. It just looks a little better on the screen if I can get things to align exactly on top of each other. Here is an example:
(* *)
(* L E F T P A N E L *)
(* *)
But it actually looks like this in the notebook in front of me:
If i move the *) in the second line one space to the left it becomes like this:
So, can not get it to align. I am using cell of type Input (standard cell).
I can't use other cell type such as Code or such. I was wondering if someone knows of a trick to get this to align.
thanks
EDIT 1: Showing font used by Input cell in the style sheet Demonstration
EDIT 2: Using code shown below by Alexey Popkov, fixed the font issue for comments, and now they are easily aligned. Here is a screen shot
EDIT 3:
Well, the party did not last for long. Using SetOptions is not allowed in a demo. Too bad, because the solution by Alexey worked well and made the comments align and look better.
Any way. Not a big deal really. can live with a little misaligned comments :)
I never really worried about this before, since I only use inline (* -- *)
comments for small comments or for commenting-out code. If I need a multiline comment, I'd split my code into smaller parts and use text cells.
That said, you could try using \[AlignmentMarker]
s on the right-most *)
:
1 + 2 + 3 + (* First three \[AlignmentMarker]*)
4 + 5 + 6 + (* Next three \[AlignmentMarker]*)
7 + 8 + 9 (* Last three \[AlignmentMarker]*)
Displays as
If you have comments in between the code (without code to the left), then maybe put it in a GridBox
(created using Ctrl-Enter
and Ctrl-,
) which is commented-out using (* ... *)
in a white font.
It's hard to give code to make the above... but here's the Box form:
Cell[BoxData[
RowBox[{"Manipulate", "[", "\[IndentingNewLine]",
RowBox[{RowBox[{RowBox[{"a", " ", "=", " ",
RowBox[{"x", "+", "1"}]}], ";", "\[IndentingNewLine]", " ",
RowBox[{StyleBox["(*", FontColor->GrayLevel[1]], "",
GridBox[{{"(*", RowBox[{"Inter", "-", RowBox[{"code", Cell[""]}]}], "*)"},
{"(*", "comments", "*)"}},
GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {},
"Rows" -> {{Baseline}}, "RowsIndexed" -> {}}], " ",
StyleBox["*)", FontColor->GrayLevel[1]]}], "\[IndentingNewLine]",
RowBox[{"{", RowBox[{"a", ",", SuperscriptBox["a", "2"]}], "}"}]}], ",",
"\[IndentingNewLine]",
RowBox[{"{", RowBox[{"x", ",", "0", ",", "1"}], "}"}]}],
"]"}]], "Input"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With