prjemian / pyRestTable

Format a nice table in reST (reStructuredText) from Python
http://prjemian.github.io/pyRestTable/
2 stars 3 forks source link

incorrect column widths #31

Closed prjemian closed 5 years ago

prjemian commented 5 years ago
import pyRestTable
table = pyRestTable.Table()
table.labels = ['h', 'k', 'l', 'mu', 'omega', 'chi', 'phi', 'gamma', 'delta']
table.addRow([0, 1, 1, 0.0, 3.4824458166048444, 22.712897698011936, 0.0, 0.0, 13.799774663132288])
table.addRow([0.0, 8.0, 0.0, 0.0, 22.31594087562736, 89.13769999977886, 0.0, 0.0, 45.158571742842376])
table.addRow([0.0, 12.0, 1.0, 0.0, 34.963469180020944, 78.33265876350477, 0.0, 0.0, 71.80070421791422])
print(table)

This is the output:

= ==== === == ================== ================== === ===== ==================
h k    l   mu omega              chi                phi gamma delta             
= ==== === == ================== ================== === ===== ==================
0 1    1   0.0 3.4824458166048444 22.712897698011936 0.0 0.0   13.799774663132288
0.0 8.0  0.0 0.0 22.31594087562736  89.13769999977886  0.0 0.0   45.158571742842376
0.0 12.0 1.0 0.0 34.963469180020944 78.33265876350477  0.0 0.0   71.80070421791422 
= ==== === == ================== ================== === ===== ==================

Columns h and mu should be wider.

prjemian commented 5 years ago

Should be this:

=== ==== === === ================== ================== === ===== ==================
h   k    l   mu  omega              chi                phi gamma delta             
=== ==== === === ================== ================== === ===== ==================
0   1    1   0.0 3.4824458166048444 22.712897698011936 0.0 0.0   13.799774663132288
0.0 8.0  0.0 0.0 22.31594087562736  89.13769999977886  0.0 0.0   45.158571742842376
0.0 12.0 1.0 0.0 34.963469180020944 78.33265876350477  0.0 0.0   71.80070421791422 
=== ==== === === ================== ================== === ===== ==================
prjemian commented 5 years ago

new unit test

prjemian commented 5 years ago

final result (not so wide due to floating point truncation as str):

=== ==== === === ============= ============= === ===== =============
h   k    l   mu  omega         chi           phi gamma delta        
=== ==== === === ============= ============= === ===== =============
0   1    1   0.0 3.4824458166  22.712897698  0.0 0.0   13.7997746631
0.0 8.0  0.0 0.0 22.3159408756 89.1376999998 0.0 0.0   45.1585717428
0.0 12.0 1.0 0.0 34.96346918   78.3326587635 0.0 0.0   71.8007042179
=== ==== === === ============= ============= === ===== =============