Cell alignment

In DocBook tables, you can control the horizontal and vertical positioning of content with a cell by using the align and valign attributes, respectively. The scope of entries affected by the attribute depends on which table element has the attribute.

Horizontal alignment

You can set horizontal alignment of cell content by setting the align attribute to any of these values:

left
center
right
char
justify

A value of char means the content should line up according to a certain character in the cell data, typically a decimal character. Then a column of numbers with decimals will have the decimals lined up. If you set align="char" for a column, you need to specify a char="." attribute (or other character) as well to tell the processor on what character to line up the entries.

The align attribute can be set on any of the following elements, so it applies to the scope of that element:

tgroup
colspec
spanspec
entry

For example, you could set align="left" in tgroup for the whole table (if you have one tgroup). Then you can set align="center" in one colspec to center all entries in that column. The following is an example.

<table><title>My table</title>
<tgroup cols="4" align="left">
<colspec colnum="1" colname="col1" colwidth="1*" />
<colspec colnum="2" colname="col2" colwidth="2*" align="center" />
<colspec colnum="3" colname="col3" colwidth="1.5*"/>
<colspec colnum="4" colname="col4" colwidth="1*" align="char" char="."/>
<thead>
...

In this example, the tgroup element sets the default alignment for the table to left. Entries in column 2 will instead be centered, and entries in column 4 are to be aligned on the decimal character in the cell data.

Vertical alignment

You can set vertical alignment of cell content by setting the valign attribute to any of these values:

top
middle
bottom

The valign attribute can be set on any of the following elements so it applies to the scope of that element:

thead
tbody
tfoot
row
entry

For example, you could set valign="top" in tbody for the whole table. Then you can set valign="middle" in one row to middle-align all cells in that row, or on a single entry to middle-align only that cell. The following is an example.

<table><title>My table</title>
<tgroup cols="4" >
...
<thead valign="bottom">
...
<tbody valign="top">
  <row valign="middle">
    <entry>...</entry>
    <entry valign="top">...</entry>
...

In this example, the row alignment overrides the tbody alignment, and then the entry alignment overrides the row alignment.

Cell rotation

The CALS rotate attribute on the entry element is not supported in the DocBook XSL stylesheets. However, it is possible to rotate the contents of individual table cells by 90 degree increments using special DocBook processing instructions. This can be useful when you have many narrow data columns that have long column headings. Rotating the column headings by 90 degrees can provide room for more columns.

This only works for printed output, and not all XSL-FO processors support such rotations. The processor must be able to support the fo:block-container element inside the fo:table-cell. The following is an example of a rotated table entry:

<entry><?dbfo orientation="90"?>
<?dbfo rotated-width="1in"?>Cell rotated left
</entry>

You have to provide two processing instructions to make this work. The <?dbfo orientation="90"?> processing instruction tells the processor to rotate the text 90 degrees counter-clockwise. The <?dbfo rotated-width="1in"?> processing instruction informs the processor of how wide the text was before it was rotated. That enables it to adjust the row-height to fit the length of the rotated text.