Skip to content

Commit 1377a64

Browse files
latex tables: Fix rendering for merged vertical cells
The table from issue #9313: .. table:: :class: standard nocolorrows +--------------------+----------------+ | 2 rows and 2 cols | 1 row x 3 cols | | +----+-----+-----+ | | A | B | C | +---+----------------+----+-----+-----+ | 1 | 2 | 3 | 4 | 5 | +---+----------------+----+-----+-----+ has merged vertical cells that notably needs to draw a vertical line on the left and right-hand side of the cells in the 2x2 grid area. If you add a column to the left of this: .. table:: :class: standard nocolorrows +---+---+----------------+----------------+ | X | 2 rows and 2 cols | 1 row x 3 cols | | | +----+-----+-----+ | | | A | B | C | +---+---+----------------+----+-----+-----+ | Y | 1 | 2 | 3 | 4 | 5 | +---+---+----------------+----+-----+-----+ then the 2x2 area should *not* draw a column line to the left of the area. We can fix this by adjusting the \multicolumn invocation to adjust when it emits the colspec. Notably, this commit does *not* consider the other broken case where a person maybe just wants the table borders like: .. tabularcolumns:: |llllll| .. table:: :class: standard nocolorrows +---+---+----------------+----------------+ | | 2 rows and 2 cols | 1 row x 3 cols | | X | +----+-----+-----+ | | | A | B | C | +---+---+----------------+----+-----+-----+ | Y | 1 | 2 | 3 | 4 | 5 | +---+---+----------------+----+-----+-----+ That has an impact in this area of the code, but to correctly consider that one has to parse out the given colspec to determine which columns have borders between them. (This line of code has a bug for this case as the colspec being emitted should be conditional if the specific column actually has it enabled, but the supporting code only determines if a vertical line is enabled anywhere rather than which columns.)
1 parent 847ad0c commit 1377a64

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sphinx/writers/latex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,10 @@ def visit_row(self, node: Element) -> None:
12541254
# insert suitable strut for equalizing row heights in given multirow
12551255
self.body.append(r'\sphinxtablestrut{%d}' % cell.cell_id)
12561256
else: # use \multicolumn for wide multirow cell
1257+
left_colsep = _colsep if cell.col == 0 else ""
12571258
self.body.append(
12581259
r'\multicolumn{%d}{%sl%s}{\sphinxtablestrut{%d}}'
1259-
% (cell.width, _colsep, _colsep, cell.cell_id)
1260+
% (cell.width, left_colsep, _colsep, cell.cell_id)
12601261
)
12611262

12621263
def depart_row(self, node: Element) -> None:

0 commit comments

Comments
 (0)