<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding a tab to label via label expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700452#M54273</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding new lines to a python label expression is trivial - just build a string with "\n" where you want the new line. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a similar way, using "\t" &lt;EM&gt;&lt;STRONG&gt;doesn't&lt;/STRONG&gt;&lt;/EM&gt; add a tab. Does anyone know a work around? How can I add tabs to a label via python label expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Jul 2014 16:25:13 GMT</pubDate>
    <dc:creator>JasonTaylor</dc:creator>
    <dc:date>2014-07-18T16:25:13Z</dc:date>
    <item>
      <title>Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700452#M54273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding new lines to a python label expression is trivial - just build a string with "\n" where you want the new line. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a similar way, using "\t" &lt;EM&gt;&lt;STRONG&gt;doesn't&lt;/STRONG&gt;&lt;/EM&gt; add a tab. Does anyone know a work around? How can I add tabs to a label via python label expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 16:25:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700452#M54273</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2014-07-18T16:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700453#M54274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It does add tabs, you have to remember though if you have a small font, that a single tab won't make much of a space between characters in your string(or an indent at the beginning).&amp;nbsp; If you need more spacing, use multiple tabs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 19:34:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700453#M54274</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-18T19:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700454#M54275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think that's how tabs are supposed to work. To illustrate my example further try the following function in a python window.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14057137158043827 jive_text_macro" jivemacro_uid="_14057137158043827"&gt;
&lt;P&gt;def FindLabel():&lt;/P&gt;
&lt;P&gt; x = "cats"&lt;/P&gt;
&lt;P&gt; y = "dogs"&lt;/P&gt;
&lt;P&gt; a = "cat"&lt;/P&gt;
&lt;P&gt; b = "dog"&lt;/P&gt;
&lt;P&gt; return x + "\t" + y&amp;nbsp; + "\n" + a + "\t" + b&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print FindLabel()&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See how the spacing is as you would expect, where the row elements justify along tab values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this label express against any feature class. See how it doesn't behave the same. It treats the tab value as a space.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14057135768749884" jivemacro_uid="_14057135768749884"&gt;
&lt;P&gt;def FindLabel():&lt;/P&gt;
&lt;P&gt; x = "cats"&lt;/P&gt;
&lt;P&gt; y = "dogs"&lt;/P&gt;
&lt;P&gt; a = "cat"&lt;/P&gt;
&lt;P&gt; b = "dog"&lt;/P&gt;
&lt;P&gt; return x + "\t" + y&amp;nbsp; + "\n" + a + "\t" + b&lt;/P&gt;


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 20:02:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700454#M54275</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2014-07-18T20:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700455#M54276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Similarly, you could add five spaces "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ".&amp;nbsp; Using that notion, you could more flexibly manage columns of text within a label by introducing the best number of spaces to ensure alignment within columns based on the length of the string in the first column.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 20:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700455#M54276</guid>
      <dc:creator>CharlieFrye</dc:creator>
      <dc:date>2014-07-18T20:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700456#M54277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah yes, repeated spaces. Like you, I thought that it would work, however try the following code in the python window and in a feature class's label expression. Comparing the two you will see that it does not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python window:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14057178273883008 jive_text_macro" jivemacro_uid="_14057178273883008" modifiedtitle="true"&gt;
&lt;P&gt;def FindLabel(): &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = "cats" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; y = "dogs" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = "cat" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = "dog" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x + " " + y&amp;nbsp; + "\n" + a + "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " + b&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print FindLabel()&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python label expression:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14057178370702628 jive_text_macro" jivemacro_uid="_14057178370702628" modifiedtitle="true"&gt;
&lt;P&gt;def FindLabel(): &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = "cats" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; y = "dogs" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = "cat" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = "dog" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x + " " + y&amp;nbsp; + "\n" + a + "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " + b&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would love to write a function that does the tab work for me, by reading the length of the string before it then applying spaces according to it's remainder of the length divided by 5. It's a lot of work but I would do it if I thought it would work. It won't because the python label expression interpreter seems to ignore repeated spaces. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think this is another short coming of python label expressions that I imagine will get worked out in later versions - hopefully since we are discussing it here. Adding columns to labels is huge in my work, I've been wanting this feature for years.&lt;/P&gt;&lt;P&gt;Just curious, are folks getting a different behavior then I described running the above code? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 21:17:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700456#M54277</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2014-07-18T21:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700457#M54278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use string formatting to make sure that all labels have the same spacing if you are adding multiple fields to your string.&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14057192502848483 jive_text_macro" jivemacro_uid="_14057192502848483"&gt;&lt;OL class="dp-py" start="1"&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;def FindLabel():&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = &lt;SPAN class="string"&gt;"cats"&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; y = &lt;SPAN class="string"&gt;"dogs"&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = &lt;SPAN class="string"&gt;"cat"&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = &lt;SPAN class="string"&gt;"dog"&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="keyword"&gt;return x.ljust(10) + y.ljust(10)&amp;nbsp; + &lt;SPAN class="string"&gt;"\n"&lt;/SPAN&gt; + a.ljust(10) +&amp;nbsp;&amp;nbsp; b&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;



&lt;/OL&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So for any length of string for x, y and a, it would add spaces after to make the entire string length 10, and be left justified.&amp;nbsp; This way all your labels would have same length and be lined up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't tried yours out yet, but this does add the spaces in my own sample map I made.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/library/string.html#deprecated-string-functions" title="https://docs.python.org/2/library/string.html#deprecated-string-functions"&gt;7.1. string — Common string operations — Python v2.7.8 documentation&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;Actually both using multiple spaces and using tabs makes wider spaces in my labels in ArcMAP then using a single space. "\t" looks about 4 spaces as opposed to a single " ".&amp;nbsp; I'm on ArcGIS 10.2.0.3348&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 21:36:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700457#M54278</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-18T21:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700458#M54279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Couple of things here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Ian your solution works, only when the Maplex engine is off. Turn maplex on and the justifications go away.&lt;/LI&gt;&lt;LI&gt;Maplex is also ignoring the multiple spaces too. Turn Maplex off and the print as expected, as my example above.&lt;/LI&gt;&lt;LI&gt;Finally the "\t" is still treated as a space with Maplex off, so no dice there.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think we have our solution. You can get tab like effects using the &lt;STRONG&gt;string.ljust()&lt;/STRONG&gt; method, but only with Maplex off. Also, as you alluded to earlier, you have to use a even spaced font, something like courier. Ian, if you change your answer to include the Maplex caveat I will mark it as the answer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 21:52:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700458#M54279</guid>
      <dc:creator>JasonTaylor</dc:creator>
      <dc:date>2014-07-18T21:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a tab to label via label expression</title>
      <link>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700459#M54280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also center or right justify with string.center or string.rjust.&amp;nbsp; Glad you found a solution that works, though its not entirely ideal.&amp;nbsp; Maplex tends to do what it wants to make your label "fit best" so it doesn't surprise me that it remove extra spaces.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 22:00:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-a-tab-to-label-via-label-expression/m-p/700459#M54280</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-18T22:00:52Z</dc:date>
    </item>
  </channel>
</rss>

