Skip to content

latex tables: Fix rendering for grid filled merged vertical cells#14024

Merged
jfbu merged 2 commits intosphinx-doc:masterfrom
tim-nordell-nimbelink:fix/latex_lines_in_merged_vertical_cells
Dec 21, 2025
Merged

latex tables: Fix rendering for grid filled merged vertical cells#14024
jfbu merged 2 commits intosphinx-doc:masterfrom
tim-nordell-nimbelink:fix/latex_lines_in_merged_vertical_cells

Conversation

@tim-nordell-nimbelink
Copy link
Contributor

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.)

Here are the three tables mentioned prior to this fix:

image

And after the fix (which just fixes the second case):

image

Notably, the 3rd case (which is not a full grid fill) leaves extra vertical lines, and an extraneous "dot".

@tim-nordell-nimbelink tim-nordell-nimbelink force-pushed the fix/latex_lines_in_merged_vertical_cells branch 2 times, most recently from 0e7c941 to 6df55e4 Compare November 3, 2025 21:59
@jfbu jfbu self-assigned this Nov 17, 2025
@jfbu jfbu added this to the 9.1.0 milestone Dec 21, 2025
@jfbu jfbu added the type:bug label Dec 21, 2025
@jfbu
Copy link
Contributor

jfbu commented Dec 21, 2025

Thank you for contribution and sorry for late. I will rebase on current master because at my locale I got a test failure

=========================== short test summary info ============================
FAILED tests/test_builders/test_build_latex.py::test_latex_labels - assert '\\caption{labeled figure}\\label{\\detokenize{index:id1}}\\label{\\...
================== 1 failed, 88 passed, 48 warnings in 21.99s ==================

which a priori is unrelated, so I need to investigate this in the proper context suitable for merging in time for 9.1.0.

The table from issue sphinx-doc#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.)
@jfbu jfbu force-pushed the fix/latex_lines_in_merged_vertical_cells branch from 6df55e4 to c3e9a22 Compare December 21, 2025 11:15
@jfbu jfbu merged commit d9fc225 into sphinx-doc:master Dec 21, 2025
26 of 28 checks passed
@tim-nordell-nimbelink
Copy link
Contributor Author

Thank you for contribution and sorry for late.

You're welcome, and no worries about it taking a while. Thanks for merging!

AA-Turner pushed a commit to pradyunsg/sphinx that referenced this pull request Dec 31, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants