Search code examples
wolfram-mathematicamathematica-frontend

how to align comments in Mathematica notebook?


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:

enter image description here

If i move the *) in the second line one space to the left it becomes like this:

enter image description here

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

enter image description here

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 enter image description here

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 :)

enter image description here


Solution

  • I do not have such problem with my installation of Mathematica 7 since it uses monospaced font "Courier New" by default for the cells with style Input. But if for some reason a non-monospaced font is used in your installation by default you can redefine the style of comments inside Notebook for using a monospaced font:

    SetOptions[EvaluationNotebook[], 
     AutoStyleOptions -> {"CommentStyle" -> {FontWeight -> Plain,
         FontColor -> GrayLevel[0.6`], ShowAutoStyles -> False, 
         ShowSyntaxStyles -> False, AutoNumberFormatting -> False, 
         FontFamily -> "Consolas"}}]