Skip to content

Commit 15da626

Browse files
authored
Correct (and cleaner) fix for longer headersalign
1 parent bd366f2 commit 15da626

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tabulate/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,11 +2234,12 @@ def tabulate(
22342234
# then specific header alignements
22352235
if headersalign is not None:
22362236
assert isinstance(headersalign, Iterable)
2237-
for idx, align in enumerate(headersalign[:len(aligns)]):
2238-
if align == "same": # same as column align
2239-
aligns_headers[headers_pad + idx] = aligns[headers_pad + idx]
2237+
for idx, align in enumerate(headersalign[:len(aligns_headers)]):
2238+
hidx = headers_pad + idx
2239+
if align == "same" and hidx < len(aligns): # same as column align
2240+
aligns_headers[hidx] = aligns[hidx]
22402241
elif align != "global":
2241-
aligns_headers[headers_pad + idx] = align
2242+
aligns_headers[hidx] = align
22422243
minwidths = [
22432244
max(minw, max(width_fn(cl) for cl in c))
22442245
for minw, c in zip(minwidths, t_cols)

0 commit comments

Comments
 (0)