Search code examples
csspython-sphinxrst2pdf

How to create a borderless table in rst2pdf?


I would like to create a borderless table in rst2pdf extension with Sphinx, but I can't seem to find a way to work around the stylesheet/css of the extension.

Any suggestions on this?


Solution

  • I just went through a "learning experience" with rst2pdf stylesheets, and while I may not have a complete answer for you, I think I can give you enough direction to get you started. A couple things I learned:

    • rst2pdf stylesheets are not CSS stylesheets, they are specific to rst2pdf and leverage (I think) some style directives from the PDF "language"; all of the source to the builtin styles can be found here
    • Custom rst2pdf stylesheets only need to define what styles you want to add or modify, or page templates that you want to modify
    • You can (and may well want) CSS and rst2pdf styles with the same name, if you want to style the same document elements differently when rendered as HTML vs. PDF

    To see how the default table style for rst2pdf is defined, you can execute the command rst2pdf --print-stylesheet or you can look at rst2pdf/styles/styles.yaml - you could then create a custom style in your stylesheet like borderless-table using that information (you may even be able to use table as the value of the parent element and override the commands element, but that is just an idea). Once you have your custom style defined, you should then be able to use it in your .rst file with the class directive:

    .. class:: borderless-table
    
    +----- your table definition here ----+
    

    Again, I haven't done this completely myself, so it's more of a partial solution or pointing in the general direction of the solution. rst2pdf is a great piece of software, but there are some devilish details that are not covered in the manual. Good luck!