python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

A "matrix" table format

Open alugowski opened this issue 2 years ago • 0 comments

May I suggest adding a "matrix" table format. I'm using this one to render sparse matrices to text and it works quite well:

TableFormat(
    lineabove=Line("┌", " ", " ", "┐"),
    linebelowheader=Line("┌", " ", " ", "┐"),
    linebetweenrows=None,
    linebelow=Line("└", " ", " ", "┘"),
    headerrow=DataRow(" ", " ", " "),
    datarow=DataRow("│", " ", "│"),
    padding=1,
    with_header_hide=["lineabove"],
)

Example output:

┌           ┐
│     3   2 │
│ 9   6     │
│     3   1 │
│ 0   5     │
└           ┘
   0     1     2     3     4     5     6
┌                                         ┐
│ 10     2          40    -5          24  │
└                                         ┘

edit: slight update to also support headers as matrix column labels

alugowski avatar Aug 24 '23 07:08 alugowski