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-11Lines changed: 24 additions & 11 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
2233
+
aligns_headers= [headersglobalalign] *len(t_cols)
2234
+
else: # default
2235
+
aligns_headers=alignsor [stralign] *len(headers)
2236
+
# then specific header alignements
2237
+
ifheadersalignisnotNone:
2238
+
assertisinstance(headersalign, Iterable)
2239
+
ifisinstance(headersalign, str):
2240
+
warnings.warn(f"As a string, `headersalign` is interpreted as {[cforcinheadersalign]}. Did you mean `headersglobalalign = \"{headersalign}\"` or `headersalign = (\"{headersalign}\",)`?", stacklevel=2)
2241
+
foridx, aligninenumerate(headersalign):
2242
+
hidx=headers_pad+idx
2243
+
ifnothidx<len(aligns_headers):
2244
+
break
2245
+
elifalign=="same"andhidx<len(aligns): # same as column align
2246
+
aligns_headers[hidx] =aligns[hidx]
2247
+
elifalign!="global":
2248
+
aligns_headers[hidx] =align
2201
2249
minwidths= [
2202
2250
max(minw, max(width_fn(cl) forclinc))
2203
2251
forminw, cinzip(minwidths, t_cols)
2204
2252
]
2205
2253
headers= [
2206
2254
_align_header(h, a, minw, width_fn(h), is_multiline, width_fn)
2207
-
forh, a, minwinzip(headers, t_aligns, minwidths)
2255
+
forh, a, minwinzip(headers, aligns_headers, minwidths)
0 commit comments