I'm having a tough time aligning text in my text box using arcpy in ArcGIS 10.3. This is my initial text:
Now I want to insert some more text to each line and align them vertically. Normally, I would insert a tab
(or two, if necessary), and basically it works, but in the exported PDF i get an annoying ?
for each tab I inserted.
I did it like this:
string.join(['UTM Zone:', '\t', utm_zone], sep='')
I also tried using the unicode sign for tab u'\u0009
with the same result. Formatting tags available in ArcMap does not help here, nor does Using text formatting tags. I guess there is some proper way of using HTML here, but I can't figure it out.
1 Answer 1
You need to use a combination of str.format()
and str.ljust()
functions to make it work. It requires some patience, and it depends on the font of the text. If you changed the font, you need also to change the settings of ljust()
.
In this example, I used Calibri
font as you mentioned in the comment.
Here is the code that worked for me in your case:
elem.text = "UTM Zone:{0}\nDatum:{1}\nEPSG code: {2}".format("38N".rjust(4),"WGS84".rjust(13),"32638".ljust(9))
Or you can use right-alignment '>'
without ljust()
and it will give you the same result:
elem.text = "UTM Zone:{:>4}\nDatum:{:>13}\nEPSG code:{:>7}".format("38N","WGS84","32638")
and here is the output in ArcGIS:
and in PDF after exporting:
Explore related questions
See similar questions with these tags.
string.join()
I just concatenate string parts with+
and it works fine:text_element.text = string1 + "\t " + string2
string.join()
is not the problem, it is the actual notation oftab
I need to figure out.