Could anybody help me to find out the solution: how is possible to create labels with subscript and superscript, based on the attribute table (polygon shape)? The example that I need to create is

enter image description here

This type of labeling is common in any kind of geological maps. I'm using QGIS v.2.18.2

I will be extremaly glad to get answer, I hope it's possible.


Superscript and subscript characters can be added manually using the copy and paste approach described in @ahmadhanb 's answer, but this question and answer details a pair of python functions that will allow such characters to be generated as part of an expression. The functions will operate on one to many digits in a string passed to them.

Example (QGIS expression):

subscr_num( 'P1')  || supscr_num( 'ub2') || subscr_num( '1')



The simultaneous sub and superscript shown at the end of the example in the question can't be generated using this approach, they would have to be offset as shown above.


If you are planning to add the subscript and superscript in the legend, then you can refer to this answer: Subscript labels in QGIS legends which add details on how to do that. However, If you want to do that in the attribute table as you stated in your question, I am afraid you can only add superscript in the attribute table, but I couldn't find a way to do the same for subscript using the same method in the answer above. The strange thing that it is only allowed to add superscript up to number 3 (from 1 to 3) but if you have values above 3 it will be converted to normal size, although it is shown in the attribute table as superscript:

enter image description here

My guess is that the System font does not have superscript above the value 3 and the subscript does not exist at all.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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