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?
Asked
Active
Viewed 6,977 times
6
-
No, it's not possible to define width in pixels. – Alderven Jan 20 '20 at 12:30
-
are there any other options to define the width? @Alderven – einmalundweg Jan 20 '20 at 12:34
-
You can define number of symbols with [texttable](https://pypi.org/project/texttable) – Alderven Jan 20 '20 at 12:41
2 Answers
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