6

So, I got a table (PrettyTable) and I want to make them as wide as I want. For example, the first column should have a width of 5px, the second of 18px, and so on... How can I do this?

einmalundweg
  • 83
  • 1
  • 6

2 Answers2

10

PrettyTable's _max_width can define column/field width in maximum characters instead.

table._max_width = {"Field 1" : 50, "Field 3" : 25}

Specify the field names and the max characters it can fit; exceeding characters wrap onto the next line.

Fields not listed will still auto adjust to long texts.

tapyokka
  • 101
  • 1
  • 5
0

In PrettyTable:

_max_width : define a dict of column width in maximum characters.

_min_width : define a dict of column width in minimum characters.

To have a dynamic column width and yet define a max column width use:

table._max_width = {"Column 1" : 50, "Column 2" : 25}

Specify the field names and the max characters it can fit; exceeding characters wrap onto the next line.

Fields not listed will still auto adjust to long texts.

To fix the width of the column using PrettyTable, both dicts _min_width and _max_width would be same.

table._min_width = {"Column 1" : 50, "Column 2" : 25}
table._max_width = {"Column 1" : 50, "Column 2" : 25}
Koedlt
  • 4,286
  • 8
  • 15
  • 33