Fix Table column widths being truncated for the first and last columns - #4900
Open
yyccPhil wants to merge 4 commits into
Open
Fix Table column widths being truncated for the first and last columns#4900yyccPhil wants to merge 4 commits into
yyccPhil wants to merge 4 commits into
Conversation
for more information, see https://pre-commit.ci
yyccPhil
marked this pull request as ready for review
July 27, 2026 03:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
This fixes the first and last columns of a
Table(and its subclassesMathTable,IntegerTable, andDecimalTable) being truncated when explicitcol_widthsare passed througharrange_in_grid_config. Grid lines and cell borders now follow each column's arranged slot instead of the bounding box of its contents, so the requested column widths are honored for every column.Closes #3446
Motivation and Explanation: Why and how do your changes improve the library?
When
col_widthsmakes a column's slot wider than its contents,arrange_in_gridcenters the (narrower) content inside the slot. However,Table._add_vertical_lines()andTable.get_cell()anchored the outer grid lines and cell borders to the content extent (get_columns()[i].get_left()/get_right()± halfh_buff) rather than to the slot. The outer columns were therefore drawn narrower than requested, and because the anchor depended on the content width, the truncation was asymmetric (a column with narrow contents was clipped more).Reproduction from the issue, rendered at width 10 with
col_widths=[3] * 6:[1.00, 1.84, 1.85, 1.85, 1.85, 1.60]— first and last columns visibly clipped.[1.667] * 6— all columns equal,col_widthshonored.Before / after
Before:

After:

The change adds a small helper,
Table._get_column_x_edges(col_index), which returns the left/right x-coordinates of a column's arranged slot:get_cell()corners are unchanged to within 1e-9 for a default table.)col_alignments("l","c","r")._add_vertical_lines()(both outer and inner lines) andget_cell()now use this helper.Links to added or changed documentation pages
No documentation pages are changed by this PR.
Further Information and Comments
test_table_col_widths_are_honored, intests/module/mobject/test_table.py, modeled on the existing regression tests there. It fails onmainand passes with this change.col_widths, so the helper intentionally keeps the previous content-based behavior for labelled tables to avoid changing their output. I'm happy to extend the fix to labelled tables as well if you'd prefer — just let me know which you'd like.This is my first contribution to Manim, so any feedback is very welcome!
Acceptance criteria
test_table_col_widths_are_honored)tests/module/mobject/test_table.pysuite + the new test)ruff checkandruff format --checkpass)col_widthspath is byte-for-byte unchanged)Reviewer Checklist