# Centered and right-justified

**URL:** <https://forum.inductiveautomation.com/t/centered-and-right-justified/16324>\
**Category:** Ignition\
**Created:** [December 14, 2017, 4:36pm UTC](https://forum.inductiveautomation.com/t/centered-and-right-justified/16324 "2017-12-14T16:36:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [December 14, 2017, 4:36pm UTC](https://forum.inductiveautomation.com/t/centered-and-right-justified/16324/1 "2017-12-14T16:36:02Z")

</div>

Is there a way to right-justify centered values? Basically, I want values in a table to be in the center of the cell so that the longest value is centered and all other values are right-justified in relation to the longest value.

Here is a picture depicting what I’m trying to accomplish:  
(As this is my first post, I’m not sure if the picture will show up correctly.)

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/db7f0ac895ce5de7e4d9749f1fb33aa35bc84147.PNG)

The first column (Value) consists of integer values centered in the column.  
The second column (Value 2) is a string representation of those same values, with spaces added to the beginning of the shorter values in an attempt to right-justify them to the longest one (“2048”).  
Unfortunately, it’s not as easy as adding one space per “missing” character since this used a proportional font.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 14, 2017, 4:44pm UTC](https://forum.inductiveautomation.com/t/centered-and-right-justified/16324/2 "2017-12-14T16:44:43Z")

</div>

I think that using a monospace font and manual padding the values is going to be the only way to achieve this.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 14, 2017, 4:55pm UTC](https://forum.inductiveautomation.com/t/centered-and-right-justified/16324/3 "2017-12-14T16:55:47Z")

</div>

Set the columns to right justification. Use a property change event on “data” to determine the longest value, then update the column attributes dataset to have a suffix of the required number of spaces.

---

<div class="post-metadata">

**Author:** ![JNelson](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JNelson](https://forum.inductiveautomation.com/u/JNelson)\
**Post date:** [December 14, 2017, 5:02pm UTC](https://forum.inductiveautomation.com/t/centered-and-right-justified/16324/4 "2017-12-14T17:02:54Z")

</div>

pturmel’s work-around seems like the best option so far, but screen resizing may cause a problem, and will likely require much more scripting than I want to do to achieve my goal. Being forced to use a monospace font is less than desirable - so not really an option.

I’ve also considered using a field within a field to accomplish this.

This definitely seems like a candidate for the next upgrade. It would surely improve the look of tables in general!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 14, 2017, 5:24pm UTC](https://forum.inductiveautomation.com/t/centered-and-right-justified/16324/5 "2017-12-14T17:24:57Z")

</div>

Try this:

```auto
if event.propertyName=='data':
    cname = 'Value2'
    cwidth = 10
    idx = event.newValue.getColumnIndex(cname)
    maxlen = max([len(str(s)) for s in event.newValue.getColumnAsList(idx)])
    cads = event.source.columnAttributesData
    idx = cads.getColumnIndex('name')
    try:
        row = list(cads.getColumnAsList(idx)).index(cname)
        spaces = max([0, int(cwidth-maxlen/2)])
        event.source.columnAttributesData = system.dataset.updateRow(cads, row, {'suffix': ' '*spaces})
    except:
        pass

```

Adjust cname and cwidth to suit. If your window is using scaling, it should work relatively well.
