[GIS] Specifying Font Size/Style in Label Expression

arcgis-desktoplabelingpython-parser

I want to create a label expression with two lines of text, this should be simple but I'm having a lot of trouble. Basically, I need the top line to be 10 pt font, and the next line to be 8pt font that is italicized.

This is what I have:

    def FindLabel ( [LABEL1], [LABEL2] ):
      return "<FNT size = '10'>" + [LABEL1] + "</FNT>" + "\n" + "<FNT size = '8'><ITA>" + [LABEL2] + "</FNT><ITA>"

This is interpreting the formatting as a string, so it's just spitting out exactly what I put in.

The piece of code below will work fine, but as soon as I add the new line everything is messed up.

    "<FNT size = '10'>" + [LABEL1] + "</FNT>"

I would like to do this using Python.

Best Answer

You fell a victim to the Expression Verification window (activated by clicking the Verify button).

The code:

def FindLabel ( [CITY_NAME] , [POP1990]  ):
  return "<CLR red='255'><FNT size = '12'>" + [CITY_NAME] + "</FNT></CLR>" + "\n" + "<CLR blue='255'><FNT size = '10'>" + [POP1990] + "</FNT></CLR>"

enter image description here

The new lines won't be rendered properly there. You have to hit OK and then Apply and actually see how labels look on the map.

enter image description here

It is also possible to include other tags such as <BOL> and <ITA>:

def FindLabel ( [CITY_NAME] , [POP1990]  ):
  return "<CLR red='255'><FNT size = '12'><ITA>" + [CITY_NAME] + "</ITA></FNT></CLR>" + "\n" + "<CLR blue='255'><FNT size = '10'><BOL>" + [POP1990] + "</BOL></FNT></CLR>"

enter image description here

Related Question