4.5 Tables and Matrices

 < Day Day Up > 



4.5 Tables and Matrices

The next section discusses the structure of tables in MathML.

The Structure of Tables

In MathML, tables and matrices can be represented using the mtable, mtr, and mtd elements. These correspond roughly to the table, tr, and td elements used for tables in HTML. The mtable element represents an entire table, the mtr element represents a single row of the table, and each mtd element represents a single cell within a row.

In addition, MathML includes an mlabeledtr element that can be used in place of any mtr element to specify a labeled row. The first argument of the mlabeledtr element specifies a label, and each subsequent argument specifies a specific cell of the row.

Here is a simple example that shows the presentation markup for a 2 by 2 matrix:

    <mrow>      <mo>(</mo>      <mtable>        <mtr>          <mtd><mn>1</mn></mtd>          <mtd><mn>2</mn></mtd>        </mtr>        <mtr>          <mtd><mn>3</mn></mtd>          <mtd><mn>4</mn></mtd>        </mtr>      </mtable>     <mo>)</mo>    </mrow> 

The mtable element accepts a large collection of attributes for adjusting various properties of the rows and columns, such as their spacing and alignment. There are 18 attributes in all (Table 4.9).

Table 4.9: Attributes of the mtable Element

Attribute

Values

Default

align

(top | bottom | center | baseline | axis)

[rownumber] axis

rowalign

(top | bottom | center | baseline | axis)+

baseline

columnalign

(left | center | right)+

center

columnwidth

(auto | number h-unit | namedspace | fit ) +

auto

width

auto | number h-unit

auto

rowspacing

(number v-unit ) +

1.0 ex

columnspacing

(number h-unit | namedspace ) +

0.8 em

rowlines

(none | solid | dashed) +

none

columnlines

(none | solid | dashed) +

none

equalrows

true | false

false

equalcolumns

true | false

false

frame

(none | solid | dashed) +

none

framespacing

(number h-unit | namedspace) (number v-unit | namedspace)

0.4 em 0.5 ex

displaystyle

true | false

false

side

left | right | leftoverlap | rightoverlap

right

minlabelspacing

number h-unit

0.8 em

groupalign

groupalignment-list-list

{left}

alignmentscope

true | false

true

For several of these attributes, the value can be a sequence of zero or more entries. In such cases, the first entry applies to the first row/column, the second entry to the second row/column, and so on. If there are fewer entries than rows/columns in the table, the last entry is repeated as many times as necessary. If there are more entries than rows/columns, the extra entries are ignored.

The meaning of most of these attributes is evident from their name. For a detailed description of each attribute, see Chapter 13.

The mtr element takes the attributes rowalign, columnalign, and groupalign. The values are normally inherited from the surrounding mtable element. You can override the inherited value by setting the attribute explicitly.

The mlabeledtr element has the same attributes as the mtr element. The only difference is that the attributes of the mlabeledtr element apply to the label as well as the individual cells in the row. To apply an attribute only to a label, you must set the attribute in the <mtd> element that surrounds the label.

The mtd element also takes the rowalign, columnalign, and groupalign attributes. The values of these attributes are normally inherited from the surrounding mtr element. You can override the inherited value by setting the attribute explicitly. In addition, the mtd element takes two other attributes: rowspan and columnspan. These can be set to an integer and allow a cell in the table to occupy a specified number of rows or columns.

Here is an example of a simple table with several attributes specified explicitly:

1

1 + x + y

1 + x

1 + y

1 + x + y

y

    <mtable columnalign='left' rowlines='solid'     columnlines='solid' frame='solid'>      <mtr>        <mtd>          <mn>1</mn>        </mtd>        <mtd>          <mn>1</mn><mo>+</mo><mi>x</mi>          <mo>+</mo><mi>y</mi>        </mtd>     </mtr>     <mtr>       <mtd>         <mn>1</mn><mo>+</mo><mi>x</mi>       </mtd>       <mtd>         <mn>1</mn><mo>+</mo><mi>y</mi>       </mtd>     </mtr>     <mtr>       <mtd>         <mn>1</mn><mo>+</mo><mi>x</mi>         <mo>+</mo><mi>y</mi>       </mtd>       <mtd>         <mi>y</mi>       </mtd>     </mtr>    </mtable> 

Labeled Rows and Numbered Equations

The mlabeledtr element can be used to implement cross-referencing and automatic numbering of equations in conjunction with XSLT processing (even though these features are not directly supported in MathML). Here is an example:

    <mtable>      <mlabeledtr >        <mtd>          <mtext>(1.7)</mtext>        </mtd>        <mtd>          <mrow>            <mi>y</mi>            <moAA *</mo>            <mrow>            <msup>              <mi>x</mi>              <mn>2</mn>            </msup>            <mo>+</mo>            <mn>1</mn>          </mrow>        </mtd>     </mlabeledtr>    </mtable> 

More information on using the id attribute to implement cross-referencing is provided in Section 6.3.

Controlling Alignment

MathML provides a sophisticated mechanism for controlling the alignment of expressions that appear in a table. You can align the content of any cell with that of other cells in the same column. Each cell can contain any number of subexpressions that can be aligned independently, along the right, left, or center, or along a decimal point.

To specify the alignment, you must take the following steps:

  1. Create alignment groups within each expression that you want to align. An alignment group is defined as any content between the start of one maligngroup element and the next maligngroup element or the end of the cell, whichever comes first.

  2. Specify a point of alignment for each alignment group. You can do this either by inserting a malignmark element or using the groupalign attribute. This attribute can be specified for an entire table or for a specific row or cell.

Let's look at a simple example. Suppose you want to display a pair of simultaneous equations so that the following items in one equation are each aligned with the corresponding items in the other equation:

  • The variables "x" and "y"

  • The operators "+" or ""

  • The "=" sign

  • The number on the right-hand side

Here is the markup for this example:

2x + y = 5
  x 2y = 1

    <mtable>      <mtr>        <mtd>          <mrow>            <mn>2</mn>            <mo>&InvisibleTimes;</mo>            <maligngroup/><mi><malignmark/>x</mi>            <maligngroup/><mo><malignmark/>+</mo>            <maligngroup/><mi><malignmark/>y</mi>            <maligngroup/><mo><malignmark/>=</mo>            <mo>-</mo>            <maligngroup/><mn><malignmark/>5</mn>          </mrow>        </mtd>      </mtr>      <mtr>        <mtd>          <mrow>            <maligngroup/><mi><malignmark/>x</mi>            <maligngroup/><mo><malignmark/>-</mo>            <mn>2</mn>            <mo>&InvisibleTimes;</mo>            <maligngroup/><mi><malignmark/>y</mi>            <maligngroup/><mo><malignmark/>=</mo>            <maligngroup/><mn><malignmark/>1</mn>          </mrow>        </mtd>      </mtr>     </mtable> 

Notice that each equation is placed in a separate cell of a table that consists of two rows and one column. In each equation, five different parts must be aligned independently. Hence, each equation contains five alignment groups, each defined using a single maligngroup element.

For each alignment group, you specify the alignment point by inserting a malignmark element in the content of the token element that contains the character to be aligned. Recall that malignmark is one of only two elements that can occur as the content of a token element (the other is mglyph).

The malignmark element takes a single attribute called edge, which defines the position of the alignment point. With the default setting edge="left", the alignment point is the left edge of the character immediately to the right of the malignmark element. With the setting edge="right", the alignment point is the right edge of the character immediately to the left of the malignmark element.

For complex expressions with a large number of alignment points, it is verbose to specify each alignment point using an explicit malignmark element. As an alternative, you can use the groupalign attribute to specify the alignment point for each alignment group.

The following markup represents the same set of equations as above but with the alignment specified using the groupalign attribute on the top-level mtable element:

2x + y = 5
  x 2y = 1

    <mtable>     <mtr groupalign="{left}">       <mtd>         <mrow>           <mn>2</mn>           <mo>&InvisibleTimes;</mo>           <maligngroup/><mi>x</mi>           <maligngroup/><mo>+</mo>           <maligngroup/><mi>y</mi>           <maligngroup/><mo>=</mo>           <mo>-</mo>           <maligngroup/><mn>5</mn>         </mrow>         </mtd>       </mtr>       <mtr>         <mtd>         <mrow>           <maligngroup/><mi>x</mi>           <maligngroup/><mo>-</mo>           <mn>2</mn>           <mo>&InvisibleTimes;</mo>           <maligngroup/><mi>y</mi>           <maligngroup/><mo>=</mo>           <maligngroup/><mn>1</mn>         </mrow>       </mtd>     </mtr>    </mtable> 

You can specify the groupalign attribute on an mtable element (for the entire table), on an mtr or mlabeledtr element (for a single row), or on an mtd element (for a single cell). If this attribute is not specified explicitly, it is inherited from the environment. Note that an alignment point specified by a malignmark element overrides the automatic specification defined by the groupalign attribute.

The alignment position for each alignment group can be specified as one of four values: left, right, center, and decimalpoint. Since each cell can contain multiple alignment groups, the groupalign attribute on an mtd element is set to a list of alignment values, each value applying to a specific alignment group. If there are more alignment groups than alignment values in the list, the last element in the list is applied to all the remaining groups. Here is an example:

    <mtd groupalign="right decimalpoint left"> 

When you specify groupalign on an mtr, mlabeledtr, or mtable element, the attribute is set to a list of list of alignment values. Each list is enclosed in curly braces to separate it from other lists. Here is an example:

    <mtr groupalign="{right decimalpoint left}                        {right left}"> 

The mtable element also takes an attribute called alignmentscope. If you set this to false, all maligngroup and malignmark elements in the table are ignored. This attribute is useful when you are representing nested tables. For example, you can use it to prevent alignment information intended for the outer table from being applied to the inner table.

In general, alignmentscope is specified as a list of Boolean values, each applying to one column of the table. For example, with the following markup, alignment elements would be recognized in the first two columns of the table but ignored in the last column:

    <mtable alignmentscope="true true false"> 



 < Day Day Up > 



The MathML Handbook
The MathML Handbook (Charles River Media Internet & Web Design)
ISBN: 1584502495
EAN: 2147483647
Year: 2003
Pages: 127
Authors: Pavi Sandhu

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net