xtables

From ConTeXt wiki
Jump to: navigation, search

< Tables Overview | tabl-xtb.lua

Contents

Extreme Tables

This is just an excerpt from the xtables manual.

“Extreme Tables” (xtable) are a variant of the “natural tables” (TABLE). They are suited for tables that span several pages. The used two-pass mechanism isn’t simple, but fast. It works only in ConTeXt MkIV, because it’s Lua-based.

List of commands

Simple sample

\startxtable
  \startxrow
    \startxcell one \stopxcell
    \startxcell two \stopxcell
  \stopxrow
  \startxrow
    \startxcell alpha \stopxcell
    \startxcell beta  \stopxcell
  \stopxrow
\stopxtable

Since xtables are a bunch of nested \frameds, you can style each unit with the known parameters.

xtables can be nested. Sub-tables inherit the properties of their enclosing cell.

XML

The following example demonstrates that we can use this mechanism in xml too. The example was provided by Thomas Schmitz. First we show how a table looks like in xml:

<table>
<tablerow>
      <tablecell>
        One
      </tablecell>
      <tablecell>
        Two
      </tablecell>
  </tablerow>
  <tablerow>
    <tablecell>
      <b>Three</b>
    </tablecell>
    <tablecell>
      Four
    </tablecell>
  </tablerow>
</table>

We need to map these elements to setups:

\startxmlsetups xml:testsetups
    \xmlsetsetup{main}{b|table|tablerow|tablecell}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:testsetups}

The setups themselves are rather simple as we don’t capture any attributes.

\startxmlsetups xml:b
  \bold{\xmlflush{#1}}
\stopxmlsetups
\startxmlsetups xml:table
  \startembeddedxtable
    \xmlflush{#1}
  \stopembeddedxtable
\stopxmlsetups
\startxmlsetups xml:tablerow
  \startxrow
    \xmlflush{#1}
  \stopxrow
\stopxmlsetups
\startxmlsetups xml:tablecell
  \startxcell
    \xmlflush{#1}
  \stopxcell
\stopxmlsetups

We now process the example. Of course it will also work for files.

\xmlprocessbuffer{main}{test}{}

Ye olde syntax

For the impatient a small additional module is provided that remaps the natural table commands onto extreme tables:

\usemodule[ntb-to-xtb]

After that:

\bTABLE \bTR
    \bTD[background=color,backgroundcolor=red] one \eTD
    \bTD[width=2cm] two \eTD
  \eTR
  \bTR
    \bTD[width=5cm] alpha \eTD
    \bTD[background=color,backgroundcolor=yellow] beta \eTD
\eTR \eTABLE

C O N T E X T G A R D E N

Personal tools
Namespaces
Variants
Actions
Help
External Help
Installation
Navigation
Toolbox