XML technologies / DocBook / Block elements / Tables / Spanning columns horizontally

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

To merge cells across columns, use the element spanspec. The total of entry elements and spanned columns must match the total in the cols attribute of tgroup. Consider the following example.

 

Example: Spanning columns

<table>
 <title>spanspec-Tabelle</title>
 <tgroup cols="3">
  <colspec colnum="1" colname="c1" align="left"/>
  <colspec colnum="2" colname="c2" align="left"/>
  <colspec colname="c3" align="left"/>
  <spanspec spanname="s1" namest="c1" nameend="c2" align="center"/>
  <tbody>
    <row>
      <entry>Eins</entry>
      <entry>Zwei</entry>
      <entry>Drei</entry>
    </row>
    <row>
      <entry namest="c1"nameend="c2">Eins und zwei</entry>
      <entry>Drei</entry>
    </row>
    <row>
      <entry spanname="s1">Eins und zwei</entry>
      <entry>Drei</entry>
    </row>
  </tbody>
 </tgroup>
</table>

Line 3: As usual: tgroup with the attribute cols
Lines 4 and 5: Column definition: name through colname, column number through colnum, alignment through align
Line 6: The attribute colnum can be omitted; counting then continues from the last colspec element.
Line 7: Defines a column span from column c1 to c2, with centered alignment. The span is named s1. Two columns are merged.
Line 15: References the start of the span with namest and its end with nameend
Line 19: Uses the column span through the attribute spanname

Result:

Table: spanspec table

Eins

Zwei

Drei

Eins und zwei

Drei

Eins und zwei

Drei

Before spanning columns, use the element colspec to specify the column name (colname) and horizontal alignment (align). In the element entry reference these columns by specifying the start and end with the attributes namest and nameend.

For frequently used spans, store their definition in the element spanspec and reference it in the element entry using the attribute spanname. In the example above, “Spanning columns”, you can see two row elements, each spanning columns one and two.

  

back to top