Cell spanning

Cell spanning means joining cells together to make a larger cell. You can join cells horizontally, vertically, or both.

Horizontal spans

To join cells horizontally, you must specify colname attributes in your colspec elements in your table. Then you use those names in an entry element to indicate the starting and ending columns for the horizontal span. You use namest to indicate the starting column name, and nameend to indicate the ending column name. The following example shows how to use them.

<table><title>Horizontal span</title>
<tgroup cols="4" >
<colspec colnum="1" colname="col1" colwidth="1*"/>
<colspec colnum="2" colname="col2" colwidth="2*"/>
<colspec colnum="3" colname="col3" colwidth="1.5*"/>
<colspec colnum="4" colname="col4" colwidth="1*"/>
<thead>
  <row>
    <entry>First column</entry>
    <entry namest="col2" nameend="col3" align="center">Span columns 2 and 3</entry>
    <entry colname="col4">Fourth column</entry>
  </row>
</thead>
<tbody>
  <row>
    <entry>Body first</entry>
    <entry>Body second</entry>
    <entry>Body third</entry>
    <entry>Body fourth</entry>
  </row>
...
 

Example 30.1. Horizontal span in table

First columnSpan columns 2 and 3Fourth column
Body firstBody secondBody thirdBody fourth
... ... ... ...

The second entry creates a horizontal span that starts in column 2 and stops in column 3. The third entry includes a colname="col4" attribute, a good practice to remind the editor that although it is the third entry, it will appear in the fourth column because of the span.

If you repeatedly use the same span in a table, you can specify a named spanspec element in tgroup to pre declare the start and end column names. Then an entry can just refer to the named spanspec, using one attribute instead of two (and reducing the possibility of error). The following is the previous example expressed with a spanspec.

<table><title>My table</title>
<tgroup cols="4" >
<colspec colnum="1" colname="col1" colwidth="1*"/>
<colspec colnum="2" colname="col2" colwidth="2*"/>
<colspec colnum="3" colname="col3" colwidth="1.5*"/>
<colspec colnum="4" colname="col4" colwidth="1*"/>
<spanspec spanname="twothree" namest="col2" nameend="col3"/>
<thead>
  <row>
    <entry>First column</entry>
    <entry spanname="twothree">Span columns 2 and 3</entry>
    <entry colname="col4">Fourth column</entry>
  </row>
</thead>
...
 

Like colspec, a spanspec element can also have an align attribute.

Vertical spans

To join cells vertically, you add a morerows attribute to an entry element. That attribute is an integer that indicates how many more rows to add to the current row for this element. The following example uses morerows:

<table><title>Vertical span</title>
<tgroup cols="4" >
<colspec colnum="1" colname="col1" colwidth="1*"/>
<colspec colnum="2" colname="col2" colwidth="2*"/>
<colspec colnum="3" colname="col3" colwidth="1.5*"/>
<colspec colnum="4" colname="col4" colwidth="1*"/>
<tbody>
  <row>
    <entry>First column</entry>
    <entry morerows="1" valign="middle">Second column</entry>
    <entry>Third column</entry>
    <entry >Fourth column</entry>
  </row>
  <row>
    <entry>Another first</entry>
    <entry colname="col3">Another third</entry>
    <entry colname="col4">Another fourth</entry>
  </row>
...
 

Example 30.2. Vertical span in table

First columnSecond columnThird columnFourth column
Another firstAnother thirdAnother fourth
............

In this example, the second entry in the first row spans downward one additional row. So the second row contains only three entry elements. The second and third entries will appear in columns 3 and 4 because the vertical span from the row above is taking up column 2. It is a good idea to tag the last two entries with colname so it is clear that the second entry in that row will appear in the third column, and so on.

You can put attributes for both horizontal and vertical span in the same entry element, and it will span in both directions. Then tagging of column names in the surrounding entries becomes even more important to prevent errors in editing.