Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alignment of characters in Notepad++

I just wondered why my m-files from MATLAB look so different when I open them with Notepad++ instead of the built-in MATLAB Editor.

It seems that in the MATLAB Editor each character has the same width. Not so in Notepad++ (even I change the language to "M").

Here's a screenshot from a file opened in Notepad++ (left) and in the MATLAB Editor (right).

enter image description here

In the MATLAB Editor all the characters in column X are exactly one below the other. They aren't in Notepad++.

I just played a bit with the tab preferences, without any success.

Is there a way to get the alignment of columns in Notepad++ the same as in the MATLAB Editor ...at least for m-files?

like image 682
Phab Avatar asked Mar 18 '15 08:03

Phab


People also ask

How do you align text in Notepad?

To make the text align to the right side, right-click inside the Notepad and select Right to left Reading order. To make the text align back to the left side, right-click again and uncheck the Right to left Reading order.

How do you align numbers in Notepad?

Ctrl+Alt+R will right align your text.

What are the 4 types of text alignments?

There are four types of paragraph alignment available in Microsoft Word — left-aligned, center-aligned, rightaligned, and justified.


2 Answers

It's because your MATLAB Editor is set to use a monospaced font such as Courier (i.e. a font where all the characters are designed to have exactly the same width), but your Notepad++ is not.

In Notepad++, you can set the font with the menu Settings -> Style Configurator. Select "MATLAB" from the language list (or in fact you may like to select "Global Styles", to do this for all languages), and set the font to a monospaced font such as Courier.

Alternatively, you may like to download a more modern programming font such as Consolas, ProFont, Monofur, Proggy, or Inconsolata. These are all monospaced, and nicer than Courier. You can use the in both Notepad++ and the MATLAB Editor.

It's possible that another issue might be that you have tab characters in your code, which are displaying with a variable width in Notepad++. You can make sure that MATLAB replaces tab characters with spaces in the MATLAB preferences (MATLAB->Editor/Debugger/Tab). To check whether you have tab characters, open the file in Notepad++ and select View->Show Symbol->Show All Characters. Tab characters will display as a short arrow, and space characters will display as a little dot. If you need to change all the tabs to spaces in an existing file, Notepad++ can do this with Edit->Blank Operations->Tab to Space.

Hope that helps!

like image 167
Sam Roberts Avatar answered Sep 26 '22 03:09

Sam Roberts


To add to Sam's answer, choosing a monospaced font specific to your environment's language is recommended. For instance, Courier New on Japanese language may not have the desired result. Choose MS Gothic (for Windows) or Osaka (for Mac) instead.

like image 20
May Kristine Avatar answered Sep 26 '22 03:09

May Kristine