Width: Fixed Column Width

This width calculator takes a fixed width per column. The width per column can be added to the calculator.

The following example creates a table and then renders the table with 3 different examples for fixed column width:

  • First example: column 1 width 10, column 2 width 20, column 3 width 30

  • Second example: column 1 width 5, column 2 width 10, column 3 width 15

  • Third example: column 1 width 3, column 2 width 5, column 3 width 7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
AsciiTable at = new AsciiTable();
at.addRule();
at.addRow("rc 11", "rc 12");
at.addRule();
at.addRow("rc 21", "rc 22");
at.addRule();
at.getContext().setWidth(13);

System.out.println(at.render());

at.getContext().setGrid(A7_Grids.minusBarPlusEquals());
System.out.println(at.render());

at.getContext().setGrid(A8_Grids.lineDoubleBlocks());
System.out.println(at.render());

at.getContext().setGrid(U8_Grids.borderDoubleLight());
System.out.println(at.render());

at.getContext().setGrid(U8_Grids.borderDouble());
System.out.println(at.render());

The resulting output for the first example:

┌──────────┬────────────────────┬──────────────────────────────┐
│col1      │col2                │col3                          │
└──────────┴────────────────────┴──────────────────────────────┘

The resulting output for the second example:

┌─────┬──────────┬───────────────┐
│col1 │col2      │col3           │
└─────┴──────────┴───────────────┘

The resulting output for the third example:

┌───┬─────┬───────┐
│col│col2 │col3   │
│1  │     │       │
└───┴─────┴───────┘