John Gill
John Gill

Reputation: 191

Is there a way to right-justify text within cells of a restructured text table?

When I put numbers in tables I generally want them to be right justified and in a fixed width font. Otherwise the numbers become hard to compare.

Is there a way to right justify fields within a table?

Eg how do I get this to render with the numbers all right justified?

.. csv-table::    
   :header: x, x*x
   3,9
   4,16
   9,81    
   10,100

Upvotes: 0

Views: 2917

Answers (2)

John Sambrook
John Sambrook

Reputation: 61

I was able to solve a similar problem. In my case, I was using a grid table.

I noticed that I could provide HTML to be used when a restructuredText "line block" was used.

I put the following in my restructuredText source file:

.. raw:: html

  <style> .line {text-align:right;} </style>

Then, in my table cells, I used the "|" character at the start (extreme left edge) of each cell that I wanted to be right-justified.

This hack does "take over" the formatting of the line block construct. That may or may not be acceptable in a given context.

Upvotes: 1

John Gill
John Gill

Reputation: 191

The best solution I have found so far is to use sphinx: http://sphinx.pocoo.org/

This supports the tabularcolumns directive, this does the right thing with latex output.

.. tabularcolumns:: |r|r|
.. csv-table::    
   :header: x, x*x
   3,9
   4,16
   9,81    
   10,100

Upvotes: 1

Related Questions