As far as I can tell, tabulate doesn't seem to have an argument for this. Maybe look into prettytable, and especially the "Changing the appearance of your table - the hard way" chapter, that allows you to be more flexible with the table style.
EDIT: texttable may be useful too, as you can define the column width. The documentation seems to be a bit lacking though, and while the ease of use may be better, the modularity seems to be a bit worse at first glance.
Answer from GregoirePelegrin on Stack OverflowAs far as I can tell, tabulate doesn't seem to have an argument for this. Maybe look into prettytable, and especially the "Changing the appearance of your table - the hard way" chapter, that allows you to be more flexible with the table style.
EDIT: texttable may be useful too, as you can define the column width. The documentation seems to be a bit lacking though, and while the ease of use may be better, the modularity seems to be a bit worse at first glance.
I was able to reduce the column separator width to a single character with:
tablefmt = "minpadding"
tabulate._table_formats[tablefmt] = tabulate.TableFormat(
lineabove=tabulate.Line("", "-", " ", ""),
linebelowheader=tabulate.Line("", "-", " ", ""),
linebetweenrows=None,
linebelow=tabulate.Line("", "-", " ", ""),
headerrow=tabulate.DataRow("", " ", ""),
datarow=tabulate.DataRow("", " ", ""),
padding=0,
with_header_hide=["lineabove", "linebelow"],
)
tabulate.multiline_formats[tablefmt] = tablefmt
tabulate.tabulate_formats = list(sorted(tabulate._table_formats.keys()))
rows = [
["Cell 1", "Cell 2"],
["Cell 3", "Cell 4a\nCell 4b"],
["Cell 5", "Cell 6"],
]
print(tabulate.tabulate(rows, headers="firstrow", tablefmt=tablefmt))
which produces:
Cell 1 Cell 2
-------- --------
Cell 3 Cell 4a
Cell 4b
Cell 5 Cell 6
» pip install tabulate