# Justifying labels inside a table

**URL:** <https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187>\
**Category:** Ruby-Gnome 2\
**Created:** [May 24, 2006, 2:13am UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187 "2006-05-24T02:13:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 24, 2006, 2:13am UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187/1 "2006-05-24T02:13:08Z")

</div>

Hi,

I have a bunch of Gtk::Labels inside a Gtk::Table. I want all the  
labels on the left hand side of the table to be left-justified. In  
other words, all the left labels’ text should be against the left  
border of the table.

Any ideas? I can’t figure out how from the documentation. I tried  
adding the label to a Gtk::Alignment object, and then packing the  
alignment object into a table, but that didn’t work.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 6, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187/2 "2008-03-06T17:26:03Z")

</div>

Joe Van D. wrote:

> Hi,
> 
> I have a bunch of Gtk::Labels inside a Gtk::Table. I want all the  
> labels on the left hand side of the table to be left-justified. In  
> other words, all the left labels’ text should be against the left  
> border of the table.
> 
> Any ideas? I can’t figure out how from the documentation. I tried  
> adding the label to a Gtk::Alignment object, and then packing the  
> alignment object into a table, but that didn’t work.

Set the horizontal packing of the labels to fill but not expand, then  
set the x align to zero for left justification and 1 for right  
justification. Hope this helps.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 4, 2009, 5:29am UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187/3 "2009-05-04T05:29:45Z")

</div>

Is it possible to do this with other widgets inside a table such as  
entry fields?

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 4, 2009, 11:34am UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187/4 "2009-05-04T11:34:00Z")

</div>

am Mon, 4 May 2009 05:29:45 +0200, tat Miles K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) der Welt kund:

Hi,

> Is it possible to do this with other widgets inside a table such as  
> entry fields?

just put the widgets in Gtk::Alignment(s)

Cheers, detlef

–  
[http://det.cable.nu](http://det.cable.nu)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 4, 2009, 2:06pm UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187/5 "2009-05-04T14:06:35Z")

</div>

am Mon, 4 May 2009 13:45:24 +0200, tat Miles K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) der Welt kund:

Hi,

> I actually had tried that like but used :
> 
> table.attach(ef,1, 2, 1,2, Gtk::SHRINK,Gtk::SHRINK,0,0)
> 
> I’m not sure why the SHRINK screws it up but doing :
> 
> table.attach\_defaults(ef,1, 2, 1,2)
> 
> works as it should.

that is, cause the alignment only allocates that much space that it’s  
child requests. If you use Gtk::SHRINK, the alignment forwards the  
“request-only-that-much-space-that-you-need” from the table cell to it’s  
child widget.

To get what you expect you have to use the attach\_defaults or

table.attach ef,1,2,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::EXPAND|Gtk::FILL,0,0

Cheers, detlef

–  
[http://det.cable.nu](http://det.cable.nu)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 4, 2009, 1:45pm UTC](https://www.ruby-forum.com/t/justifying-labels-inside-a-table/95187/6 "2009-05-04T13:45:24Z")

</div>

Detlef R. wrote:

> am Mon, 4 May 2009 05:29:45 +0200, tat Miles K.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) der Welt kund:
> 
> Hi,
> 
> > Is it possible to do this with other widgets inside a table such as  
> > entry fields?
> 
> just put the widgets in Gtk::Alignment(s)

Thanks mate.

I actually had tried that like but used :

table.attach(ef,1, 2, 1,2, Gtk::SHRINK,Gtk::SHRINK,0,0)

I’m not sure why the SHRINK screws it up but doing :

table.attach\_defaults(ef,1, 2, 1,2)

works as it should.

Cheers.
