You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -666,18 +666,31 @@ Ver2 19.2
666
666
667
667
### Custom column alignment
668
668
669
-
`tabulate` allows a custom column alignment to override the above. The
670
-
`colalign` argument can be a list or a tuple of `stralign` named
671
-
arguments. Possible column alignments are: `right`, `center`, `left`,
672
-
`decimal` (only for numbers), and `None` (to disable alignment).
673
-
Omitting an alignment uses the default. For example:
669
+
`tabulate` allows a custom column alignment to override the smart alignment described above.
670
+
Use `colglobalalign` to define a global setting. Possible alignments are: `right`, `center`, `left`, `decimal` (only for numbers).
671
+
Furthermore, you can define `colalign` for column-specific alignment as a list or a tuple. Possible values are `global` (keeps global setting), `right`, `center`, `left`, `decimal` (only for numbers), `None` (to disable alignment). Missing alignments are treated as `global`.
Headers' alignment can be defined separately from columns'. Like for columns, you can use:
684
+
-`headersglobalalign` to define a header-specific global alignment setting. Possible values are `right`, `center`, `left`, `None` (to follow column alignment),
685
+
-`headersalign` list or tuple to further specify header-wise alignment. Possible values are `global` (keeps global setting), `same` (follow column alignment), `right`, `center`, `left`, `None` (to disable alignment). Missing alignments are treated as `global`.
warnings.warn(f"As a string, `colalign` is interpreted as {[cforcincolalign]}. Did you mean `colglobalalign = \"{colalign}\"` or `colalign = (\"{colalign}\",)`?", stacklevel=2)
ifheadersglobalalignisnotNone: # if global alignment provided
2235
+
aligns_headers= [headersglobalalign] *len(t_cols)
2236
+
else: # default
2237
+
aligns_headers=alignsor [stralign] *len(headers)
2238
+
# then specific header alignements
2239
+
ifheadersalignisnotNone:
2240
+
assertisinstance(headersalign, Iterable)
2241
+
ifisinstance(headersalign, str):
2242
+
warnings.warn(f"As a string, `headersalign` is interpreted as {[cforcinheadersalign]}. Did you mean `headersglobalalign = \"{headersalign}\"` or `headersalign = (\"{headersalign}\",)`?", stacklevel=2)
2243
+
foridx, aligninenumerate(headersalign):
2244
+
hidx=headers_pad+idx
2245
+
ifnothidx<len(aligns_headers):
2246
+
break
2247
+
elifalign=="same"andhidx<len(aligns): # same as column align
2248
+
aligns_headers[hidx] =aligns[hidx]
2249
+
elifalign!="global":
2250
+
aligns_headers[hidx] =align
2203
2251
minwidths= [
2204
2252
max(minw, max(width_fn(cl) forclinc))
2205
2253
forminw, cinzip(minwidths, t_cols)
2206
2254
]
2207
2255
headers= [
2208
2256
_align_header(h, a, minw, width_fn(h), is_multiline, width_fn)
2209
-
forh, a, minwinzip(headers, t_aligns, minwidths)
2257
+
forh, a, minwinzip(headers, aligns_headers, minwidths)
0 commit comments