How to CENTER TEXT?????



  • I can’t believe I’ve spent TEN MINUTES trying to figure out how to CENTER a line of text! (Still haven’t found it!) Sheeeesh!



  • Notepad++ is not a text processing software, it is a plain text editor. This kind of software usually has no “center text” feature.



  • @Michael-Scott
    you can tell about future request here https://github.com/cpmcgrath/codealignment



  • @dinkumoil Strange that it is listed everywhere, including here, for example (https://kinsta.com/blog/best-text-editors/) as one of the top 5 or 10 “text editors”.
    I’ve been in advertising and in marketing for over 50 years and been working with PC’s and Mac’s since the mid-80’s.

    When did “they” change the definition of “text”?

    Also, strange that Notepadd++ has commands for flush left and flush right…but not CENTER?

    Oh well.



  • @Michael-Scott said in How to CENTER TEXT???:

    @dinkumoil Strange that it is listed everywhere, including here, for example (https://kinsta.com/blog/best-text-editors/) as one of the top 5 or 10 “text editors”.

    Everywhere? Doubtful. But it is an excellent text editor, and I consider it one of the best. You’re allowed your own opinion.

    I’ve been in advertising and in marketing for over 50 years and been working with PC’s and Mac’s since the mid-80’s.

    I’m sorry. That sounds like you’ve led a difficult life. I wouldn’t wish 50 years of advertising, marketing, PCs, and Macs on even my worst enemy, let alone a random stranger on the internet. (As an engineer, I cannot image a much worse career than having to deal with advertising and marketing for 50 years. I guess customer service [people!] or manual labor [tired!] might be worse, but I’m not sure.)

    When did “they” change the definition of “text”?

    Word processors (MS Word, OpenOffice Writer, etc) are made to be able to fiddle with alignments, fonts, and presentation stuff.

    Text editors (Notepad++, MS notepad, SciTE, vim, emacs) are made for actually editing plaintext. Their emphasis is on editing the text that will be in a plaintext file on disk; the how it looks is focused on making it easier to edit the text. Some text editors (all but MS notepad, in that list) are enhanced to work better as source-code editors – so they can apply colors, run macros, and help make coding easier.

    “Centering” is not really a concept suited to text editors, because that depends on context and graphical issues (font sizes, proportional vs fixed-width, document width, etc). To “center” text, even beyond those hurdles, how do you expect a text editor to indicate “center this”? Word processors do it by embedding some sort of code around the text that says “this text is centered” – but a text-editor’s job is to save the text, and just the text, to the disk, so it cannot use formatting codes. The only way it could “center” is to insert some sort of whitespace characters before the text. But then, is it really centered? No, because if you edit the number of characters in that line of text, the number of spaces would have to change. And if you opened it in a different person’s copy of Notepad++, or a competitor’s text editor, would it be centered? Not likely, though you may get lucky.

    If you want to save formatting codes (like center, justify, bold, font size, etc), you need a word processor. If you care about getting specific text into a plaintext file, for easy standards-driven transport or for sending to a compiler/interpreter, then a text editor is right for you. If you want to do it with automation, and have things like syntax highlighting, to make sure that the textual code you are writing/editing makes sense, and to help make it more efficient, then a text editor like Notepad++ is right for you.

    I am curious: how do you define the “right” or “center” for a plaintext document? Do you use the old early-80s definition, where many command-line-based computers had 40 character wide screens (like the TI99/4-A I grew up on)? Or the dot-matrix-printer standard 80 character wide paper? Or 120 character like I usually set as my minimum command-prompt-window sizes in windows and linux? Does this change when you change the printer settings from portrait to landscape and back? Do you want it to keep track of how font size influences characters per line? Does Notepad++ always know when a zoom setting somewhere has made it so it’s 80-character-wide line only takes up half the width of the printed page? or twice the width of the printed page?

    Note: you could make stabs at defining those and overcoming each of my contadictions to the idea of “centering” for plaintext… but all it takes is another person who disagrees with your definition to prove that it’s not really centered plaintext.

    Also, strange that Notepadd++ has commands for flush left and flush right…but not CENTER?

    Strange that it’s written all over the software and this forum, but you haven’t noticed there’s only one “d” in “Notepad++”.

    But, beyond that, I’m not sure where these “flush left” and “flush right” commands you mention are located in Notepad++: I’ve never noticed them. Notepad++ has Edit > Blank Operations > Trim Leading Space, which is effectively a “flush left”. But … Trim Trailing Space, while it removes extra whitespace from the end of a line, isn’t a “flush right”.

    Oh well.

    Indeed. Good luck.



  • @Michael-Scott said in How to CENTER TEXT???:

    working with PC’s and Mac’s since the mid-80’s.

    OK, that means approximately 35 years of working with computers. In all that time you never noticed the difference between a text/word processor like MS Word and a plaintext editor like MS Notepad or the old DOS edit.com? You surely have to be a marketing guy …



  • The following could explain it all. He could be this guy:

    c7581b91-1f59-4290-bea7-ca8bf691a9ae-image.png

    Non-Americans will probably not understand this (sorry).



  • @PeterJones said in How to CENTER TEXT???:

    @Michael-Scott said in How to CENTER TEXT???:

    @dinkumoil Strange that it is listed everywhere, including here, for example (https://kinsta.com/blog/best-text-editors/) as one of the top 5 or 10 “text editors”.

    Everywhere? Doubtful. But it is an excellent text editor, and I consider it one of the best. You’re allowed your own opinion.

    I’ve been in advertising and in marketing for over 50 years and been working with PC’s and Mac’s since the mid-80’s.

    I’m sorry. That sounds like you’ve led a difficult life. I wouldn’t wish 50 years of advertising, marketing, PCs, and Macs on even my worst enemy, let alone a random stranger on the internet. (As an engineer, I cannot image a much worse career than having to deal with advertising and marketing for 50 years. I guess customer service [people!] or manual labor [tired!] might be worse, but I’m not sure.)

    When did “they” change the definition of “text”?

    Word processors (MS Word, OpenOffice Writer, etc) are made to be able to fiddle with alignments, fonts, and presentation stuff.

    Text editors (Notepad++, MS notepad, SciTE, vim, emacs) are made for actually editing plaintext. Their emphasis is on editing the text that will be in a plaintext file on disk; the how it looks is focused on making it easier to edit the text. Some text editors (all but MS notepad, in that list) are enhanced to work better as source-code editors – so they can apply colors, run macros, and help make coding easier.

    “Centering” is not really a concept suited to text editors, because that depends on context and graphical issues (font sizes, proportional vs fixed-width, document width, etc). To “center” text, even beyond those hurdles, how do you expect a text editor to indicate “center this”? Word processors do it by embedding some sort of code around the text that says “this text is centered” – but a text-editor’s job is to save the text, and just the text, to the disk, so it cannot use formatting codes. The only way it could “center” is to insert some sort of whitespace characters before the text. But then, is it really centered? No, because if you edit the number of characters in that line of text, the number of spaces would have to change. And if you opened it in a different person’s copy of Notepad++, or a competitor’s text editor, would it be centered? Not likely, though you may get lucky.

    If you want to save formatting codes (like center, justify, bold, font size, etc), you need a word processor. If you care about getting specific text into a plaintext file, for easy standards-driven transport or for sending to a compiler/interpreter, then a text editor is right for you. If you want to do it with automation, and have things like syntax highlighting, to make sure that the textual code you are writing/editing makes sense, and to help make it more efficient, then a text editor like Notepad++ is right for you.

    I am curious: how do you define the “right” or “center” for a plaintext document? Do you use the old early-80s definition, where many command-line-based computers had 40 character wide screens (like the TI99/4-A I grew up on)? Or the dot-matrix-printer standard 80 character wide paper? Or 120 character like I usually set as my minimum command-prompt-window sizes in windows and linux? Does this change when you change the printer settings from portrait to landscape and back? Do you want it to keep track of how font size influences characters per line? Does Notepad++ always know when a zoom setting somewhere has made it so it’s 80-character-wide line only takes up half the width of the printed page? or twice the width of the printed page?

    Note: you could make stabs at defining those and overcoming each of my contadictions to the idea of “centering” for plaintext… but all it takes is another person who disagrees with your definition to prove that it’s not really centered plaintext.

    Also, strange that Notepadd++ has commands for flush left and flush right…but not CENTER?

    Strange that it’s written all over the software and this forum, but you haven’t noticed there’s only one “d” in “Notepad++”.

    But, beyond that, I’m not sure where these “flush left” and “flush right” commands you mention are located in Notepad++: I’ve never noticed them. Notepad++ has Edit > Blank Operations > Trim Leading Space, which is effectively a “flush left”. But … Trim Trailing Space, while it removes extra whitespace from the end of a line, isn’t a “flush right”.

    Oh well.

    Indeed. Good luck.

    Well, then, here ya go:

    "Anna BolReplied on October 26, 2016
    Moderator
    Hi Robyn,

    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.

    Feel free to get back to us if you have other concerns. "

    Oh, and, Notepad++ with two d’s is what we in the journalistic world call a “typo”…sometimes a “mistake”, something engineers never perform. (Oops: forgot about the Hindenburg…the Titanic and Chernobyl. Oh, and that pesky St. Francis dam, the Tacoma bridge, and, of course, the Space Shuttle. Doh!



  • @Michael-Scott said in How to CENTER TEXT???:

    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.

    To me functions like “flush/align left” (or right) or “center text” can exist in a text editor, but they typically would change the actual text by inserting/removing space characters to perform the desired action. Contrast this with a word-processor that would typically just insert a “code” to do the wanted thing (as mentioned before).

    Using the functions you mentioned, which are more properly found on the View menu as:

    • Text Direction RTL
    • Text Direction LTR

    (pet peeve, not sure why these aren’t shown as Right-to-Left and Left-to-Right)

    …all you are doing is changing the view, not the actual data. This is fairly clear (try printing after changing to RTL!). Maybe this is what you want, but these really aren’t “justification” commands, and that’s probably why there is no “center”.



  • @Michael-Scott said in How to CENTER TEXT???:

    “typo”…sometimes a “mistake”, something engineers never perform.

    I never claimed I never make typos or other mistakes. My years of contributions to this forum probably include many counter examples to belie such a claim of perfection, had I made such a claim. And my status as an engineer (or yours in advertising and marketing with decades of PC and Mac experience) has no bearing on expertise with any given tool, or need for help or technical clarification.

    I made the joke about feeling sorry for you, because you said,

    I’ve been in advertising and in marketing for over 50 years and been working with PC’s and Mac’s since the mid-80’s.

    The only reasons I could see for making a statement like that were either you were trying to justify why your beliefs about what features should be in a text editor should outweigh our beliefs about what should be in a text editor (and, more importantly, should outweigh the development team’s beliefs about what should be in this text editor), or because you were otherwise trying to imply some special condition or circumstance that comes with years of experience. Instead of trying to respond to such justifications or implications on a similar level, I decided to humorously pretend to interpret them as a cry for pity. Sometimes, my sense of humor falls flat on others.

    I noticed you focused nearly completely on that one statement by me, rather than on all the technical arguments I made. But since that’s the only productive side of any such conversation, I’ll try to focus there.

    Using right-to-left reading order settings seems like a strange way to “justify” text. It doesn’t technically change the underlying text, so it’s a feature of the display settings of the text editor, rather than a feature that affects how the text is stored on disk. So it right-justifies the display; but if you opened the file on another computer that doesn’t share you settings, or in another text editor, there is nothing inherent in the text that is “right justified”. If you consider that “right justification” (or if that’s enough “right justification” for your needs), that’s fine. In modern Notepad++, those don’t appear to be in the default RightClick context menu anymore (I tried looking through the code history for contextMenu.xml, but couldn’t see the last time they were)… but they are in the View menu, under Text Direction RTL and Text Direction LTR.

    As far as permanently (ie, on disk) centering or right-justifying text: that’s not something that can be natively done within Notepad++'s current codebase. One could submit a feature request (explained in this linked FAQ), but one would have to be polite in the request, and would have to accept that there’s a high likelihood that the development team won’t prioritize it, or will out-and-out reject the feature request.

    When I searched for “text editor with center command”, I found that the Atom text editor has a “package” which has a configurable “Preferred Line Length Setting”, and the ability to left-align, center-align, right-align, justify, and dejustify text (I assume those last two add extra spaces between words, or collapse those extra spaces). It looks like that package adds space characters in appropriate places, depending on that setting.

    I can see two ways to accomplish the same thing in Notepad++: use a plugin (it may have to be written; though if you have a 32-bit Notepad++, you might try the TextFX plugin – I did a quick look though and couldn’t find a “center” or “right align” command, but I’m not a TextFX expert). Alternately, using a scripting plugin (like PythonScript or LuaScript), you could write a script which would add or remove spaces from the start of the line to accomplish right-align or centering, assuming a given line-length.

    To make up for my bad humor earlier, I will give you the PythonScript solution. If 80 is not your preferred width, then change that variable in the given script.

    # encoding=utf-8
    """in response to https://notepad-plus-plus.org/community/topic/18536/
    
    Centers text based on PreferredWidth setting in script
    
    If the cursor is on a line, just center that line.
    If there is a multiline selection, center all the lines.
    
    If a line to be centered is longer than PreferredWidth, it will just trim all leading and trailing spaces
    """
    from Npp import *
    
    PreferredWidth = 80
    
    s0 = editor.getSelectionStart()
    s1 = editor.getSelectionEnd()
    l0 = editor.lineFromPosition(s0)
    l1 = editor.lineFromPosition(s1)
    
    if l1>l0 and s1==editor.positionFromLine(l1):
        # multiline selection ends at the beginning of a line
        #   going to assume that the final line isn't really part of the selection
        #   (ie, select from start of line1 to start of line3, you really just want 1-2 selected)
        l1 = l1 - 1
    
    editor.beginUndoAction()
    
    for myLine in range(l0,l1+1):
        # grab the current line, sans trailing and leading whitespace/newlines
        str = editor.getLine(myLine).rstrip().lstrip()
    
        # add appropriate leading spaces for centering
        if len(str) < PreferredWidth:
            nInsert = (PreferredWidth-len(str)) // 2
            str = (' ' * nInsert) + str
            #print('\t=>"{}"\n'.format(str))
            editor.replaceLine(myLine,str)  # this will keep the original EOL (CR,LF,CRLF,or EOF)
    
    editor.endUndoAction()
    

Log in to reply