Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables with different styles #1070

Open
rousku opened this issue Jul 1, 2022 · 3 comments
Open

Tables with different styles #1070

rousku opened this issue Jul 1, 2022 · 3 comments

Comments

@rousku
Copy link

rousku commented Jul 1, 2022

The table-body style applies to all tables in the document. So there is no way to have one table with body cells aligned to the left and another table were cell contents are aligned to the right.

@akrabat
Copy link
Member

akrabat commented Jul 1, 2022

You may find https://akrabat.com/styling-rst2pdf-tables/ useful.

@rousku
Copy link
Author

rousku commented Jul 3, 2022

table_test.rst:

+-----------+-----------+-----------+
| Heading 1 | Heading 2 | Heading 3 |
+===========+===========+===========+
| a         | b         | c         |
|           |           |           |
| aa        |           |           |
+-----------+-----------+-----------+
| d         | e         | f         |
+-----------+-----------+-----------+

table_test.style:

styles:
    table:
        commands: []
            [VALIGN, [ 0, 0 ], [ -1, -1 ], MIDDLE ]
            [ROWBACKGROUNDS, [0, 0], [-1, -1], [white]]
            [LINEBELOW, [0, 0], [-1, 0], 0.5, black]
            [BOTTOMPADDING, [0, 1], [-1, -1], 5]
            [TOPPADDING, [0, 1], [-1, -1], 5]
            [ALIGN, [ 0, 0 ], [ -1, -1 ], RIGHT ]

rst2pdf -s table_test.style table_test.rst table_test.pdf, table_test.pdf:
image

The ALIGN command is not taking the effect of aligning the text in the table cells to the right.

If my table_style.style is instead:

styles:
    table:
        commands: []
            [VALIGN, [ 0, 0 ], [ -1, -1 ], MIDDLE ]
            [ROWBACKGROUNDS, [0, 0], [-1, -1], [white]]
            [LINEBELOW, [0, 0], [-1, 0], 0.5, black]
            [BOTTOMPADDING, [0, 1], [-1, -1], 5]
            [TOPPADDING, [0, 1], [-1, -1], 5]
            [ALIGN, [ 0, 0 ], [ -1, -1 ], RIGHT ]

    table-body:
        alignment: RIGHT

The output is:
image

EDIT:
$ rst2pdf --version
0.99

@akrabat
Copy link
Member

akrabat commented Jul 10, 2022

In rst, the class directive applies to the next element. This makes it a pain to style elements within a table as you need to apply the class within the cell. For instance:

+----------+------------------+
|   Item   |      Value       |
+==========+==================+
|          | .. class:: right |
|          |                  |
| Widget 1 | 1.20             |
+----------+------------------+
|          | .. class:: right |
|          |                  |
| Widget 2 | 2.30             |
+----------+------------------+

To apply a style to nested element I imagine that we'd have to come up with a more complicated and extensible style system so you can do the CSS equivalent of mytable > table-body in the style file so that you could add the mytable class above the table definition and then apply styles to table-body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants