StructuredText has support for generating tables with a simpler markup than HTML. Prior to Zope 2.4, Structured Text (classic) used markup like this:

 | a | b |
 | c | d |

Renders as:

| a | b | | c | d |

Now, Structured Text (NG) uses this markup:

 |-------|
 | a | b |
 |=======|
 | c | d |
 |-------|

Renders as:

a

b

c

d

Also, Structured Text in ZWiki supports this variant; the + at the corners makes it easier to edit in Emacs. It may not be worth deviating from the standard though:

 +---+---+
 | a | b |
 +---+---+
 | c | d |
 +---+---+

Renders as:

a

b

c

d

You can influence horizontal and vertical justification by positioning your text within the cell. Also, you can use a wider cell when you need to. Other variations may cause Structured Text not to recognize the table or even give an error.

If you're editing these a lot, you definitely want help from something like picture-mode. There's also table.el . In some cases it may be quicker to use :: and fixed width text, as above.

Notes and examples

(from FranOReilly)

Basically, you need to "draw" the table borders and cell borders with | and - characters. The important bits are that the first and last lines are |---------------| to represent the top and bottom borders and row separators; that the left and right borders of each row are bounded by | and that cells are separated by |. Although it doesn't seem to be very fussy about exact alignment, it is probably best to make sure the rows, columns line up correctly at least for readers of the code.

Here are three examples:

 |--------------------------|
 | Col1 | Col2 | col3       |
 |--------------------------|
 |This is a spanning row    |
 |--------------------------|
 |Cell1 | Cell 2 | Cell 3   |
 |--------------------------|

Col1

Col2

col3

This is a spanning row

Cell1

Cell 2

Cell 3

This one is a table with table headers (the first row separator line is made of = characters:

 |--------------|
 |Date | Time   |
 |==============|
 |20/5 | 12:00  |
 |--------------|
 |21/5 | 13:15  |
 |--------------|

Date

Time

20/5

12:00

21/5

13:15

Here is an example of a table embedded in a table from the StructuredTextWiki:StructuredTextNGRules:

 |-------------------------------------------------|
 | Function  | Documentation                       |
 |=================================================|
 | '__str__' | This method converts the            |
 |           |  the object to a string.            |
 |           |                                     |
 |           | - Blah                              |
 |           |                                     |
 |           | - Blaf                              |
 |           |                                     |
 |           |       |--------------------------|  |
 |           |       |  Name   | Favorite       |  |
 |           |       |         | Color          |  |
 |           |       |==========================|  |
 |           |       | Jim     |  Red           |  |
 |           |       |--------------------------|  |
 |           |       | John    |  Blue          |  |
 |           |       |--------------------------|  |
 |-------------------------------------------------|

Function

Documentation

__str__

This method converts the the object to a string.

  • Blah
  • Blaf

    Name

    Favorite Color

    Jim

    Red

    John

    Blue

The generated tables aren't very compact or pretty.

Nested Example :

 +------------------------+
 | <center>               |
 |  Top-o-the-World,      |
 |                        |
 |    MA!!!</center>      |
 +========================+
 |                        |
 |                        |
 | +-------------------+  |
 | |                   |  |
 | |       self        |  |
 | |                   |  |
 | | +---------------+ |  |
 | | |               | |  |
 | | |  centered?    | |  |
 | | |               | |  |
 | | +---------------+ |  |
 | |                   |  |
 | +-------------------+  |
 |                        |
 +------------------------+

renders as:

Top-o-the-World,

MA!!!

self

centered?

The "+" way doesn't need the right wall of the box, although it needs all 4 corners. This leads to some interesting possibilities...

hmmm... This should be a stx table

hmmm :

 +-+
 | hmmm... This should be a stx table.
 +-+

+- | hmmm2... This is not +-

hmmm2:

 +-
 | hmmm2... This is not
 +-

empty?:

nested?:

|

  • This is a checkbox item

This is another

eratic block endings:

a

b

c

d

Other examples: QuickReference

http://wikipedia.org/wiki/Wikipedia:How_to_use_tables is an excellent guide for creating tables with HTML.


comments:

numbers dont render -- Thu, 03 Mar 2005 01:50:52 -0800 reply
if you have a table like this:

no

qty

the 12 and 15 come out as 1. and 1.

Agreed -- Tue, 10 May 2005 09:00:45 -0700 reply

Yeah the date example seems to deliberately skirt round this issue. For instance if the example read:

Date

Time

12:00

13:15

Then it would not have worked. It seems that if the contents of the table are numbers (and lets face it this is often the case) then they are treated as a numbered list. Maybe the default behaviour should be to not interpret numbers as a numbered list within a table cell?

Agreed -- Tue, 10 May 2005 09:03:58 -0700 reply
In fact having written the example without commenting it, the error is shown, lets try again:

 |--------------|
 |Date | Time   |
 |==============|
 |20   | 12:00  |
 |--------------|
 |21   | 13:15  |
 |--------------|