table fit
Various options are available to check the shape of the table (different row width across the table rows) and, if specified to do fitting work by padding too short rows or truncating too long rows.
Indirect parameter passing is disabled
2-3
No. | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1. input |
string | Name of existing table | ||||||||||||
2. input |
string | Option Option, one of the following:
Effect of the options on the table:
| ||||||||||||
Opt. 3. input |
string | Padding contents The contents will be used to pad up the short rows in order to align them as specified. With the option trim, contents in every row are checked from right to left if they equal to the specified padding contents (or blank if not specified). The extraneous cells will be deleted and the rows made shorter. Default value: '' (blank) |
Type | Description |
---|---|
boolean | Table is rectangular true if the entire table is rectangular, i.e. number of columns per row is the same everywhere. |
table initialize( t,
{ { A, B, C, D, E, F },
{ A1, B1, C1, D1, E1, F1 },
{ A2, B2, C2, D2, E2, F2, G2, H2 },
{ A3, B3, C3, D3, '', '', '', '' },
{ A4, B4, C4, D4, '', '', '', '' },
{ A5, B5, C5, D5, '', '' },
{ A6, B6, C6, D6 },
{ '', '' },
{ A9, B9 } } );
table insert columns( t, Width, "", 0 );
table process ( t, [Width] = table row width( t, row() )-1 );
echo("Original table:" );
table list( t );
define procedure ( demonstrate table fit, {{ option, string }} )
{
table copy table ( t, u );
padding[] = select if ( option[]!=trim, "-", "" );
rect[] = table fit ( u, option[], padding[] );
echo( "Fit table to '", option[],"' (rectangular = ", rect[],"):" );
table process ( u, [Width] = table row width( u, row() )-1 );
table list (u);
}
demonstrate table fit (check );
demonstrate table fit (min table width );
demonstrate table fit (min header width );
demonstrate table fit (max table width );
demonstrate table fit (equal header width );
demonstrate table fit (trim );
Original table:
0 : Width | A | B | C | D | E | F | |
1 : 6 | A1 | B1 | C1 | D1 | E1 | F1 | |
2 : 8 | A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2
3 : 8 | A3 | B3 | C3 | D3 | | | |
4 : 8 | A4 | B4 | C4 | D4 | | | |
5 : 6 | A5 | B5 | C5 | D5 | | | |
6 : 4 | A6 | B6 | C6 | D6 | | | |
7 : 2 | | | | | | | |
8 : 2 | A9 | B9 | | | | | |
Fit table to 'check' (rectangular = false):
0 : Width | A | B | C | D | E | F | |
1 : 6 | A1 | B1 | C1 | D1 | E1 | F1 | |
2 : 8 | A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2
3 : 8 | A3 | B3 | C3 | D3 | | | |
4 : 8 | A4 | B4 | C4 | D4 | | | |
5 : 6 | A5 | B5 | C5 | D5 | | | |
6 : 4 | A6 | B6 | C6 | D6 | | | |
7 : 2 | | | | | | | |
8 : 2 | A9 | B9 | | | | | |
Fit table to 'min table width' (rectangular = true):
0 : Width | A | B
1 : 2 | A1 | B1
2 : 2 | A2 | B2
3 : 2 | A3 | B3
4 : 2 | A4 | B4
5 : 2 | A5 | B5
6 : 2 | A6 | B6
7 : 2 | |
8 : 2 | A9 | B9
Fit table to 'min header width' (rectangular = false):
0 : Width | A | B | C | D | E | F | |
1 : 6 | A1 | B1 | C1 | D1 | E1 | F1 | |
2 : 8 | A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2
3 : 8 | A3 | B3 | C3 | D3 | | | |
4 : 8 | A4 | B4 | C4 | D4 | | | |
5 : 6 | A5 | B5 | C5 | D5 | | | |
6 : 6 | A6 | B6 | C6 | D6 | - | - | |
7 : 6 | | | - | - | - | - | |
8 : 6 | A9 | B9 | - | - | - | - | |
Fit table to 'max table width' (rectangular = true):
0 : Width | A | B | C | D | E | F | - | -
1 : 8 | A1 | B1 | C1 | D1 | E1 | F1 | - | -
2 : 8 | A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2
3 : 8 | A3 | B3 | C3 | D3 | | | |
4 : 8 | A4 | B4 | C4 | D4 | | | |
5 : 8 | A5 | B5 | C5 | D5 | | | - | -
6 : 8 | A6 | B6 | C6 | D6 | - | - | - | -
7 : 8 | | | - | - | - | - | - | -
8 : 8 | A9 | B9 | - | - | - | - | - | -
Fit table to 'equal header width' (rectangular = true):
0 : Width | A | B | C | D | E | F
1 : 6 | A1 | B1 | C1 | D1 | E1 | F1
2 : 6 | A2 | B2 | C2 | D2 | E2 | F2
3 : 6 | A3 | B3 | C3 | D3 | |
4 : 6 | A4 | B4 | C4 | D4 | |
5 : 6 | A5 | B5 | C5 | D5 | |
6 : 6 | A6 | B6 | C6 | D6 | - | -
7 : 6 | | | - | - | - | -
8 : 6 | A9 | B9 | - | - | - | -
Fit table to 'trim' (rectangular = false):
0 : Width | A | B | C | D | E | F | |
1 : 6 | A1 | B1 | C1 | D1 | E1 | F1 | |
2 : 8 | A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2
3 : 4 | A3 | B3 | C3 | D3 | | | |
4 : 4 | A4 | B4 | C4 | D4 | | | |
5 : 4 | A5 | B5 | C5 | D5 | | | |
6 : 4 | A6 | B6 | C6 | D6 | | | |
7 : 0 | | | | | | | |
8 : 2 | A9 | B9 | | | | | |