1

The correct convention for displaying measurements in text is to have a space between the number and the unit such as 10 m. When presenting attribute tables, in a layout for example the "m" often gets split onto a new line if you have fixed column widths. Is there a way to keep the number and its unit together?

As shown below, the second row doesn't look great.

enter image description here

16
  • 1
    Can you give a visual example? This isn't a problem I have ever experienced.
    – Matt
    Commented Nov 30, 2023 at 14:28
  • 1
    I meant a visual example of it happening in your attribute table. Not to address this specific problem, but another option could be to use an integer field (which is easier to perform calculations on if needs be) and append the ' m' wherever it is needed in maps/reports etc.
    – Matt
    Commented Nov 30, 2023 at 15:06
  • 1
    Not sure what exactly you're asking: I mean in your case, the width of the column is too small to show the whole text. You're not asking about that, are you? I mean drawing the broder of the column a bit to the right to make a larger width could solve that issue.
    – Babel
    Commented Nov 30, 2023 at 15:16
  • 2
    What does you screenshot show? It does not look like the default attribute table view in QGIS. The attribute table in QGIS has flexible column widths and I don't see a use case where you use it for presenting your results. However, you can still replace the space before "m" with a no-break space (e.g. copy&paste it from an external editor using the input methods described in @J.R's link) manually or using replace() with a regular expression. If you are talking about a representation of the attribute table contents e.g. in a print layout, you have more options.
    – winnewoerp
    Commented Dec 1, 2023 at 4:57
  • 1
    So you are not talking about necessarily replacing the normal space by a non-breaking space in the attribute table itself, but in a graphical representation of the table, e.g. in a layout. Correct? The main source of misunderstanding here is that what is generally referred to as the "attribute table" in QGIS is only what you get e.g. by double-clicking a vector layer. The term is normally not used for any other (graphical) representations of the attribute data e.g. in layouts, even when presented as a table.
    – winnewoerp
    Commented Dec 4, 2023 at 12:53

2 Answers 2

1

Depending on how you defined the value and where you use it, you might have accidentally entered a space for Wrap on character that converts the space into a line break:

The label is generated here with the expression value || ' m', where value is the field containing a number. So the label would look like 1.6 m, however, when a space is entered in the Wrap on character box, you will get a new line instead of the space. As the space is invisible, this can generate confusion. enter image description here

2
  • The question is about attribute tables
    – Sethinacan
    Commented Nov 30, 2023 at 15:01
  • So the line break is in the attribute table itself? Can you show a screenshot?
    – Babel
    Commented Nov 30, 2023 at 15:03
1

So if you have a linebreak in a textfield in the attribute table, you can remove it by either manually delete it or use field calculator with this expression:

replace ("field_name" ,'\n' ,' ')

It replaces a line brake ("New line" marker '\n') with a space.

enter image description here

4
  • There are no line breaks in the text
    – Sethinacan
    Commented Nov 30, 2023 at 15:13
  • So then what is the problem? I thought you wanted to get rid of line breaks? Maybe I don't understand the question...
    – Babel
    Commented Nov 30, 2023 at 15:14
  • 2
    @Sethinacan, do not be rude. Babel does his best to help you based on all the details you provided :)
    – Taras
    Commented Nov 30, 2023 at 15:18
  • @Taras being concise may be interpreted as rude when that is not the intention
    – Sethinacan
    Commented Nov 30, 2023 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.