1

I'm using Tabulate in order to print data in a table format. I'm trying to figure out whether I could somehow add comments in between rows without any impact on the alignment.

That's how it is:

 1. ItemA     A: 0   B: 4    C: 8   D: 8   E: 0   
 2. ItemB     A: 0   B: 0    C: 6   D: 0   E: 0   
 3. ItemC     A: 2   B: -3   C: 1   D: 8   E: 0   
 4. ItemD     A: 8   B: 0    C: 5   D: 0   E: 0

I want to turn it to this:

 1. ItemA     A: 0   B: 4    C: 8   D: 8   E: 0   
 Some comment
 2. ItemB     A: 0   B: 0    C: 6   D: 0   E: 0
 3. ItemC     A: 2   B: -3   C: 1   D: 8   E: 0
 Some other very long comment  
 5. ItemD     A: 8   B: 0    C: 5   D: 0   E: 0

If I try to add it as an extra row then it pushes all the elements of the second column, like this:

 1. ItemA                           A: 0   B: 4    C: 8   D: 8   E: 0   
 Some comment
 2. ItemB                           A: 0   B: 0    C: 6   D: 0   E: 0
 3. ItemC                           A: 2   B: -3   C: 1   D: 8   E: 0
 Some other very very long comment  
 5. ItemD                           A: 8   B: 0    C: 5   D: 0   E: 0

which I don't want at all

NOTE: There won't be a comment below every row

Thanks for your time!

Nick M
  • 69
  • 7
  • Without seeing what you've currently done, it's very hard to help. https://stackoverflow.com/help/minimal-reproducible-example – blueteeth Dec 16 '21 at 02:58
  • I'm not doing anything special, what you do with tabulate is provide a list of lists to a function and everything else just happens. The above is created like this `ItemList.append([ ['ItemA', 'A:0', 'B:1'], [ItemB, 'A:1', 'B:2']] print(tabulate(ItemList))` – Nick M Dec 16 '21 at 10:23
  • And this isn't a site where people will just give you the answer. If you want a solution, please edit your question with what you've tried, and what result that gets you. If I'm going to try and help, I want something I can easily paste to get to the same level you're at. – blueteeth Dec 19 '21 at 13:02

0 Answers0