2

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.

  • Although you've been a member here for a while, I note you still haven't taken the new user tour which states there should be only one question per Question. Please ask your second question separately. – Midavalo Apr 6 '17 at 16:03
  • 1
    @Tom your final italic tag should be </ITA> not <ITA>. – Fezter Apr 7 '17 at 0:44
3

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

  • That does work, however, the problem still persists. When I add the <BOL> or <ITA> tags, it still displays the full string of code, on the map and in the verification window. – Tom Apr 6 '17 at 17:17
  • Added a sample with ITA and BOL, shouldn't be a problem. Make sure you use the right syntax; easy to miss a character. – Alex Tereshenkov Apr 6 '17 at 18:57

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.