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 grid table) in which the rightmost column reports contains numbers that I would like to right-align, but I couldn't find how to achieve that.
============ ===================== Event Score variation ============ ===================== Event 1 +100 Event 2 -25 Event 3 -400 ============ =====================
I would be happy to switch to a grid table if this would allow me to solve the problem.
Use width:100% on the table and the middle column. You could also set width:100% on the last column's style and td align="right" on the last column. Then you can insert more columns in the middle while the spacing still works.
Select the table chart, click in the corner of a table column, and then click in the column formatting bar until you reach the desired alignment. The control shows the alignment you are about to set. Click to center the text. Click to align the text to the right.
On the Home tab, click Paragraph, and then click Align. Select the Align with option and then select the paragraph tag pertaining to the column one paragraph. Click OK.
Table data defaults to left alignment; table headers to center. In order to change the alignment in one cell, insert the appropriate "ALIGN=" attribute within the code for that cell. In order to change the alignment in all cells in a row, insert the appropriate alignment attribute within the code for that row.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With