Skip to content

left, right, and center-aligned Markdown tables #53

Closed
RaSan147/python-tabulate
#11

Description

@tanimislam

I realize that Markdown is a mess, but for tablefmt="github" with stralign argument, the header line (which goes as -----------) can be modified as the following:

  • stralign="left": header lines will have :---------.
  • stralign="right": header lines will have ---------:.
  • stralign="center": header lines have :--------:.

Activity

  1. samueljsb commented on Aug 5, 2022

    @samueljsb

    I just had a look at implementing this and realised that this is exactly what the 'pipe' format does. The README even points out that the 'github' format is the 'pipe' format without alignment markers, although I missed that the first time I read through the patterns.

  2. kdeldycke commented on Oct 6, 2022

    @kdeldycke
    Contributor

    Had the same issue trying to produce a GitHub table with alignment directives. I ended up with a workaround to emulate that behavior. For reference, my hackish code is available at: https://github.com/kdeldycke/meta-package-manager/blob/af261b7194c592bbd45a6910bed8063fa6c59fbe/meta_package_manager/inventory.py#L56-L87

  3. kdeldycke commented on Apr 4, 2023

    @kdeldycke
    Contributor

    For reference, I proposed a PR to address this issue at: #261

  4. astanin commented on Sep 27, 2024

    @astanin
    Owner

    I suppose this feature is now covered by colon_grid format, pull request #341

  5. kdeldycke commented on Feb 2, 2026

    @kdeldycke
    Contributor

    PR #341 that has been merged upstream does not fix this issue.

    Here is the proof:

    $ uvx -v --from "git+https://github.com/astanin/python-tabulate.git" python -c "from tabulate import tabulate; print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age'], tablefmt='github', colalign=('left', 'right')))"
    ...
    DEBUG Fetching source distribution from Git: https://github.com/astanin/python-tabulate.git
    ...
    DEBUG Searching for a compatible version of tabulate @ git+https://github.com/astanin/python-tabulate.git (*)
    DEBUG Looking at `.dist-info` at: ~/.cache/uv/archive-v0/YogKmSah5W05iH5lIr1AV/lib/python3.14t/site-packages/tabulate-0.9.1.dev158+g74885be91.dist-info
    
    | Name   |   Age |
    |--------|-------|
    | Alice  |    24 |
    | Bob    |    19 |
    

    If the issue I reported was addressed, we would have this printed instead:

    | Name   |   Age |
    |:-------|------:|
    | Alice  |    24 |
    | Bob    |    19 |

    Can we re-open this issue and consider re-opening #261 ?

  6. kdeldycke commented on Mar 5, 2026

    @kdeldycke
    Contributor

    FYI, this is not fixed in the brand new v0.10 release, so I made a new PR at: #410

  7. added a commit that references this issue on Mar 5, 2026
    8014ec6
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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions