Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating nested tables in python tabulate

I want to create a LaTeX table as follows in python:

duck    small    dog    small
        medium          medium
        large           large

how would I do that?

The list I have looks like:

lis=['dog',['small','medium','large],'duck',['small','medium','large']]
like image 498
laila Avatar asked Sep 19 '25 07:09

laila


1 Answers

I figured this out.

The idea is not to treat this as nested tables but as one table. In this case a table with 4 columns, so you reformat your list as:

lis=[('dog','small','duck','small'),('','medium','','medium'),('','large','','large)]

then use the tabulate package:

from tabulate import tabulate
print(tabulate(lis))

voila:

---  ------  ----  ------
dog  small   duck  small
     medium        medium
     large         large
---  ------  ----  ------
like image 78
laila Avatar answered Sep 21 '25 04:09

laila