Skip to content

Expand typing for Title field in Table object #4172

Open
mariam851/rich
#1

Description

@klaw-rii

Description

When building tables in a CLI program I am working on, I have varying sized tables that are smaller than the console width. I was using the Rule object as a separator between them, but I also had a Text object centered in the middle of the Rule object as sort of a title. The issue came in that the Rule was spanning the entire width of the console instead of just the Table's width. I then passed the Rule in for the title field which then restricted the Rule to the Table's width. This worked cleaning except for the typing. The title field is currently set to Union[str, Text], optional and I think it would benefit from a less strict typing.

Suggested Change

Update the Title arg in the Table Class with a more open typing that accepts more than just str and Text objects.

Benefits

There are currently a couple of other ways I can think of handling this. One would be putting both the Rule and the Table in a Table.grid object. Another way is determining the width of the Table and then building a Text object the same size. Both seem cumbersome and overall would be more cleanly solved by just passing a Rule in for the title of a Table.

Activity

  1. krishnaverma001 commented on Jun 19, 2026

    @krishnaverma001

    Hi! I've prepared a fix for this issue. My branch is available at:
    https://github.com/krishnaverma001/rich/tree/fix-table-title-typing

    Changes include:

    • Updated Table.title and Table.caption typing from TextType to RenderableType
    • Added tests in test_rule_in_table.py and test_table.py

    This allows users to pass Rule, Panel, or any renderable as table titles.

    Could someone please review my changes or add me as a collaborator so I can open the PR?

    Thank you!

  2. added 2 commits that reference this issue on Jul 4, 2026
    3911f1b
    5f3ee07
  3. Jyotish08 commented on Jul 28, 2026

    @Jyotish08

    Hi! I have prepared a fix for this issue with updating Table.title and Table.caption types to RenderableType, along with passing unit tests. Since repository PR interactions are currently limited to collaborators, my branch is available on my fork here: https://github.com/Jyotish08/rich/tree/fix-table-title-typing. Please let me know if you'd like me to open a PR when interactions reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions