Inkscape.org
Beginners' Questions How to automatically vertical center align the text inside a rectangle
  1. #1
    ollydbg ollydbg @ollydbg

    Hi, there is a post in stackexchange.com(see here: https://graphicdesign.stackexchange.com/questions/136385/text-at-the-center-of-a-rectangle-in-inkscape ) which shows how to center align the text inside a rectangle. This is a quite important feature which allow us to draw flow chart inside the Inkscape.

    While, the answers in that post still lack a key feature that if a rectangle get size changed, the text is not vertically center aligned any more, so I have to click the vertical alignment button again, see the gif file of the screen cast here: https://imgur.com/i3S5Idb

    My question is, is there automatic way to align the text in vertical direction after the size of the rectangle get changed?

    It is tedious if I need to click the align button again and again after changing the rectangle size.

    I see a similar post ten years ago: How to center text in a box - InkscapeForum.com — https://alpha.inkscape.org/vectors/www.inkscapeforum.com/viewtopicecd8.html?t=4084

    But I don't see there are no solutions there.

     

  2. #2
    Paddy_CAD Paddy_CAD @Paddy_CAD

    In the CAD world your request is known as a constraint or constrained geometry or parametric modelling.  There's no equivalent in Inkscape but the live path effects might fall into the category.  The alignment tools are only concerned with placement.  The shapes are not glued together.  Editing one shape will not modify another (except for clones and LPEs).

    There are strategies to preserve alignment when manipulating shapes .  First and foremost, groups will preserve the relative positions of all member shapes.  Using the shift key when transforming to preserve symmetry around the rotation centre.  Use clones to modify several shapes in unison.  Use guides and snapping to restore alignments when they change.

    Preserve Alignment
  3. #3
    ollydbg ollydbg @ollydbg
    *

    @Paddy_CAD

    Thanks for the reply. Indeed, this is kind of constraint. You gives me many good suggestions. thanks.

    When the text is Flow into Frame, I would expect there are 9 options for the text alignment(See the attachment image), but in-fact, there is currently 3 in Inkscape.

    Is there any thing I can do? Maybe, a feature request? Or a custom plugin/add-on to support those 9 text alignments.

  4. #4
    ollydbg ollydbg @ollydbg

    When I hold the "shift" key, and adjust the size of the rectangle, I see that the rectangle just transforming to preserve symmetry around the rotation centre, but the inner "flowed text" does not keep the vertical center aligned while I change the rectangle size. It looks like the text keeps the fixed vertical distance to the top line of the rectangle.

    After the adjust of the rectangle size, I still need to select the text, and click the "Center on horizontal axis" in the align and distribute panel.

  5. #5
    Paddy_CAD Paddy_CAD @Paddy_CAD
    *

    @ ollydbg

    This is a late reply, but maybe it's useful.  It's not so much a solution as a partial workaround.  Here's a way to preserve the horizontal alignment when you change the text frame.  There's no equivalent for vertical text centering but the vertical offset is preserved.

    [Edit] The svg file renders properly in Inkscape but not here in the forum.  I'm adding a png to prove it.

    Flowed Text
  6. #6
    onepixelman onepixelman @onepixelman

    I need vertical alignment inside text boxes, as well. How can we make this a feature request?

  7. #7
    Paddy_CAD Paddy_CAD @Paddy_CAD

    Halloween approaches, when forum posts of old can push aside the veil of death.

  8. #8
    Paddy_CAD Paddy_CAD @Paddy_CAD

    @onepixelman. I'm not sure what you mean by "vertical alignment inside text boxes". Perhaps you can upload a screenshot or a link to what you want to achieve.

  9. #9
    onepixelman onepixelman @onepixelman

    I am just wanting the same thing that previous posters have mentioned on this thread. I need a way to center text vertically, like you would inside a cell in Microsoft Word or Excel. I am using Pele Nilsson's countersheets extension, so text is being added to these textboxes automatically, and, depending on the text added, it will change the vertical centering. However, if there was a way to align text vertically, in the same way that you can align text centered (horizontally), it should negate this problem. 

    I see your example above, but it looks like the text is still not centered vertically.

  10. #10
    ollydbg ollydbg @ollydbg
    *

    Hi, onepixelman, you last comments shown empty here, but I do receive the email notification which contains your comment:

     

    I am just wanting the same thing that previous posters have mentioned on this thread. I need a way to center text vertically, like you would inside a cell in 
    Microsoft Word or Excel. I am using Pele Nilsson's countersheets extension, so text is being added to these textboxes automatically, and, depending on the text 
    added, it will change the vertical centering. However, if there was a way to align text vertically, in the same way that you can align text centered 
    (horizontally), it should negate this problem. I see your example above, but it looks like the text is still not centered vertically.

     

  11. #11
    ollydbg ollydbg @ollydbg

    Hi, Paddy_CAD.

    First, thanks for your reply.

    I post the question last year, but I still can't find a way to solve my question right now.  Under Microsoft word, it is very simple to put a text in side the rectangle, and it is very easy to create flow-chart, but under inkscape, it is really hard to do this.

  12. #12
    Paddy_CAD Paddy_CAD @Paddy_CAD
    *

    Use snapping and guides to align text frames vertically and horizontally.

    To align text with the bottom or middle of a frame, select the text and the frame then use the Align and Distribute dialog [shift+ctrl+a]. Unlike horizontal alignment, vertical alignment is not preserved when the text changes and you may need to repeat it after editing.

    Here's a minor update to my old tutorial.

    Flowed Text
    Flowed Text
  13. #13
    onepixelman onepixelman @onepixelman

    Yes, I appreciate you showing how to manually align text vertically, but I am looking for an automated way to do that. As I mentioned, I am using a plug-in that automatically places text. Is it not possible to add a feature request to be able to position text in the way that @ollydbg mentions above with his table tools dialogue? It allows you to have text flow from top left, top center, top right, center left, center center, center right, bottom left, bottom center, bottom right. The one that I am looking for is center, center.

  14. #14
    inklinea inklinea @inklinea⛰️

    It cannot be done automatically without editing the Inkscape source code. Mapping a resize event to an align function.

    A request would have to be raised at https://gitlab.com/inkscape/inbox/-/issues

    However it could be done with an extension mapped to a keyboard shortcut. 

    At least for a flowed text box inside a shape. Since the text element in the frame contains shape-inside:url(#rect705)

    Would be a case of comparing bounding boxes - and moving the inner text element.

     

  15. #15
    ollydbg ollydbg @ollydbg

    Hi, @inklinea, from my point of view, if you have ever wrote some flowchart, it is very common a user has to tweak the size of the rectangle. So, it is also very common operation to put the text in the middle of the rectangle (which we called both vertical center alignment and horizontal center alignment) after tweaking the size of the rectangle.

    How ever, maybe not much people are using inkscape to draw the flowchart, so this feature is not implemented. Instead, the similar feature is already exists in many document editor(such as Microsoft word).

     

     

  16. #16
    bleke bleke @bleke

    If you are making a flowchart, maybe you would be better off using Dia - another open source program.

    You could export your chart to SVG and open it in Inkscape for further editing.

    https://en.wikipedia.org/wiki/Dia_(software)

  17. #17
    inklinea inklinea @inklinea⛰️

    Yes, I know the online flowchart builders do that too.

    It's not hard to implement in an extension, but I don't know how hard it would be in the main codebase.

    Certainly I hate those diamond boxes - text never looks good in them - even with the best tools.

    Centre Vertically
  18. #18
    Tyler Durden Tyler Durden @TylerDurden

    Fwiw, even Ai has only recently enabled this feature.

    There are some SVG properties that might be helpful, and related CSS... not sure how useful the info is: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/alignment-baseline

  19. #19
    inklinea inklinea @inklinea⛰️
    🙌👍

    Getting text bounding boxes for flowed text is super slow on windows as it requires a command call.

    Much quicker on Ubuntu ( as in the video a couple of posts up ) 

    Anyway, another thing exists in the world.

    https://gitlab.com/inklinea/centre-flowed-text

  20. #20
    bleke bleke @bleke

    You're a plugin creating machine, inklinea. :)

  21. #21
    inklinea inklinea @inklinea⛰️
    *

    I perhaps should make it loop, so if you have shift clicked lots of them they are centred at the same time. 

    I would probably only take 0.5 seconds to do more - it's the command call that causes it to be slow.

    :)

    I'm going to try to replace the command call with the excellent TextParser written by David Burghoff https://inkscape.org/~burghoff/%E2%98%85scientific-inkscape

    Will be hugely faster if I can. 

  22. #22
    inklinea inklinea @inklinea⛰️
    🙏🙏*🙏

    I've updated the extension.

    It will filter anything you select ( for example Edit>Select All In All Layers ) 

    Then it will apply the horizontal and vertical centring. 

    If you select the `textparser` method, it should be fast.

    [Whoops, I double clicked on that icon - thanking myself lol]

  23. #23
    Tyler Durden Tyler Durden @TylerDurden

    It's ok to thank yourself... as many times as you like!   😄

  24. #24
    inklinea inklinea @inklinea⛰️
    🏆

    I've posted an update to allow a choice between:

    Horizontal centring only, Vertical Centring only, or Both.

    Choice between TextParser and Inkscape --query-all methods. ( which was bugged due to my bad coding )

    On Windows TextParser is very fast - but does have a slight problem if you are using special horizontally condensed fonts.

    Inkscape --query-all is the most accurate, but a bit slow on windows.

    If it breaks let me know - I will prob put this on the main Inkscape.org website if okay :)

Inkscape Inkscape.org Inkscape Forum Beginners' Questions How to automatically vertical center align the text inside a rectangle