How to right-align columns content in reStructuredText simple tables?

后端 未结 3 664
感动是毒
感动是毒 2021-02-05 03:03

I\'m editing the documentation for a project of mine using Sphinx, which in turn uses reStructuredText as markup language.

I have a simple table (as opposed to

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 03:39

    Sadly I don't think rst offers that ability... the table styling options are rather limited. That said, if you're rendering to HTML, you could add a custom stylesheet with a css rule such as:

    table.right-align-right-col td:last-child {
        text-align: right
    }
    

    and then add the directive:

    .. rst-class:: right-align-right-col
    

    right above your table in the rst file. It's clunky, but it should work.


    update 2013-2-6: I've since needed to accomplish this myself, and came up with a more permanent solution. The cloud_sptheme.ext.table_styling Sphinx extension adds directives for doing column alignment, per-column css classes, and number of other table styling tricks. Despite being packaged as part of the "cloud" Sphinx theme, it should work with any Sphinx theme.

提交回复
热议问题