Vertical Headers in RestructuredText Tables

In RestructuredText, you can display the title bar in a table similar to this one (taken from the documentation :

+------------------------+------------+----------+----------+ | Header row, column 1 | Header 2 | Header 3 | Header 4 | | (header rows optional) | | | | +========================+============+==========+==========+ | body row 1, column 1 | column 2 | column 3 | column 4 | +------------------------+------------+----------+----------+ | body row 2 | Cells may span columns. | +------------------------+------------+---------------------+ | body row 3 | Cells may | - Table cells | +------------------------+ span rows. | - contain | | body row 4 | | - body elements. | +------------------------+------------+---------------------+ 

Is it possible to do something similar with the first column? An example that obviously does not work can be as follows (note the double, as at the end of column 1):

 +------------------------++------------+----------+----------+ | Header row, column 1 || Header 2 | Header 3 | Header 4 | | (header rows optional) || | | | +========================++============+==========+==========+ | body row 1, column 1 || column 2 | column 3 | column 4 | +------------------------++------------+----------+----------+ | body row 2 || Cells may span columns. | +------------------------++------------+---------------------+ | body row 3 || Cells may | - Table cells | +------------------------++ span rows. | - contain | | body row 4 || | - body elements. | +------------------------++------------+---------------------+ 
+8
restructuredtext
source share
1 answer

You can achieve this using the list-table directive with the stub-columns option. Or you can even combine stub-columns with header-rows . See http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table for details. This is a simple example hereinafter:

 .. list-table :: Sample list table
    : widths: 10 20 20
    : header-rows: 1
    : stub-columns: 1

    * - 
      - Column 1
      - Column 2
    * - Row 1
      - Hello
      - World!
    * - Row 2
      - Hello
      - List Table!
    * - Row 3
      - This
      - Works

The obvious drawback is that you need to maintain the contents of the table as a list, which may not be as convenient as in ordinary simple tables. So, you can check the csv-table directive here: http://docutils.sourceforge.net/docs/ref/rst/directives.html#id1 , which also has the stub-columns option.

If you need to adhere to the usual table syntax - sorry, I'm not sure if this is possible. As a workaround, you can use strong text for the text in the first column :-)

+13
source share

All Articles