Bezoar 26 March 2008 I wanted to reformat a text table to reduce the width of each column and NOT truncate the contents. I turned to tcllib's matrix and report packages to accomplish this as I mistakenly thought that the report package would word wrap automatically. This unfortunately is not the case. However by using textutils you can preprocess the cell data and get the result you want this example script does that.

 package require struct::matrix 
 package require report
 package require textutil 

 set mytable(0,0)  "Elements"      
 set mytable(0,1)  "Element A"          
 set mytable(0,2)  "Element B"   
 set mytable(0,3)  "Element C"   
 set mytable(0,4)  "Element D"   
 set mytable(1,0)  "Description" 
 set mytable(1,1)  "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676  9 10 11 12 13 141516" 
 set mytable(1,2)  "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676  9 10 11 12 13 141516"
 set mytable(1,3)  "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676  9 10 11 12 13 141516"
 set mytable(1,4)  "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676  9 10 11 12 13 141516" 

 proc getReport { name  columns style args } {
     ::report::defstyle simpletable {} {
         data        set [split "[string repeat "| "   [columns]]|"]
         top        set [split "[string repeat "+ - " [columns]]+"]
         bottom        set [top get]
         top        enable
         bottom        enable
     }
     set r [ report::report $name $columns style simpletable ]
    return $r
 } 
 proc setReportColumnSizes { name columnlist dataArray } {
     upvar $dataArray a 
     r sizes  $columnlist
     for { set i 0 }  { $i < [llength $columnlist] } { incr i } {
         foreach index [ array names a $i,* ] {
             set a($index) [ textutil::adjust $a($index) -length [lindex $columnlist $i ] -justify left -strictlength true ]
         }
     }
 }
 set columns 2
 set rows [ expr [ llength [ array names mytable ] ] / $columns ] 
 set r [  getReport r $columns simpletable ]
 set sizelist { 15 25 } 
 setReportColumnSizes r $sizelist mytable
 set m [ struct::matrix m ] 
 m add columns $columns
 m add rows $rows
 m link tablex
 set tabledatalist ""
 array set tablex [array get mytable]
 puts "[r printmatrix m ]"

Results in :

 +---------------+-------------------------+
 |Elements       |Description              |
 |Element A      |ABCDEFGHIJKLMENOP QRST   |
 |               |UVW X YZ 1234 5676 9 10  |
 |               |11 12 13 141516          |
 |Element B      |ABCDEFGHIJKLMENOP QRST   |
 |               |UVW X YZ 1234 5676 9 10  |
 |               |11 12 13 141516          |
 |Element C      |ABCDEFGHIJKLMENOP QRST   |
 |               |UVW X YZ 1234 5676 9 10  |
 |               |11 12 13 141516          |
 |Element D      |ABCDEFGHIJKLMENOP QRST   |
 |               |UVW X YZ 1234 5676 9 10  |
 |               |11 12 13 141516          |
 +---------------+-------------------------+

if run without textutil pre-procesing the data is truncated :

 +---------------+-------------------------+
 |Elements       |Description              |
 |Element A      |676  9 10 11 12 13 141516|
 |Element B      |676  9 10 11 12 13 141516|
 |Element C      |676  9 10 11 12 13 141516|
 |Element D      |676  9 10 11 12 13 141516|
 +---------------+-------------------------+