GNU TeXmacsUser manualReferenceAboutEnglish
Typesetting tables

1.Overview

Tables are typeset by the module

Typeset/Table/

, with the classes table_rep and cell_rep declared in

Typeset/Table/table.hpp

. A table is not handled by the bridges: it is always typeset as a whole, as part of the paragraph containing it. There are three entry points in

Typeset/Table/table.cpp

:

box typeset_as_table (edit_env env, tree t, path ip)
(table as a single box)

Used by concater_rep::typeset_table for tables inside a line (the usual case for tabular, matrices and similar environments). It returns one box.

array<box> typeset_as_var_table (edit_env env, tree t, path ip)
(table as a list of rows)

Used by typeset_concat_or_table when a paragraph consists of a table. If the table variable table-hyphen is not n, the table is returned as one box per row, so that the paragraph formatter can put each row on its own line and the page breaker can break the table across pages. Otherwise a single box is returned.

lazy make_lazy_table (edit_env env, tree t, path ip)
(lazy table)

Used when a table occurs in vertical material handled through lazy structures (floats, multi-paragraph cells, GUI containers). The lazy_table_rep answers width queries with table_rep::compute_width and produces a vertical stream of rows once the available width is known; a width given in par units is resolved at that moment.

When an inline table is wider than the limit env->table_max (the environment variable math-table-limit) and has no explicit width, and all its cells are simple, concater_rep::typeset_table gives up the two-dimensional layout and typesets the cells inline, separated by commas and semicolons, so that the result can be broken across lines.

2.The phases of table typesetting

All entry points perform the same sequence of steps (the lazy version postpones the last ones until produce is called):

table T (env);
T->typeset (t, ip);
T->handle_decorations ();
T->handle_span ();
T->merge_borders ();
T->position_columns (true);
T->finish_horizontal ();
T->position_rows ();
T->finish ();          // or var_finish ()

2.1.Typesetting the cells

table_rep::typeset strips the enclosing tformat tags and accumulates their twith and cwith formatting directives (together with the inherited cell-format of the environment) into a single tformat. format_table reads the table variables (table-width, table-hmode, paddings, borders, alignments, table-hyphen, origin). typeset_table and typeset_row then create a cell for each entry, with the variables cell-row-nr and cell-col-nr set in the environment; extract_format selects the formatting directives which apply to each row and cell.

cell_rep::typeset reads the cell variables (format_cell), applies the non-cell- cwith variables to the environment (cell_local_begin), and typesets the content:

A cell may also have a cell-decoration, a small table with a tmarker which surrounds the cell; it is typeset as a table D with status 1.

2.2.Decorations, spans and borders

handle_decorations expands decorated cells: the rows and columns of the decoration tables are inserted into the main table, so that decorations are aligned with the other cells. handle_span clears the cells covered by cells with cell-row-span or cell-col-span larger than one. merge_borders makes the borders of adjacent cells consistent: each border is the maximum of the borders declared by the cells on both sides.

2.3.Horizontal positioning

position_columns (bool large) determines the widths of the columns. compute_widths asks each cell for three quantities with cell_rep::compute_width: its total width mw and, for cells aligned on an anchor (upper case alignments such as L, C, R, or alignment on a named position inside the cell), the widths lw and rw to the left and right of that anchor. The width of a column is the maximum over its cells; spanning cells enlarge their first column if necessary. For multi-paragraph cells, the width is obtained by querying the lazy structure with make_query_vstream_width, i.e. the natural width of its contents.

If the table has a prescribed width (table-width with a mode other than auto), the extra space is distributed over the columns by the static function blow_up, proportionally to the cell-hpart values of the columns, and without making a column wider than its natural width unless all columns have reached it. Nested tables are then positioned with the width of their column, and the horizontal alignment table-halign determines the horizontal offset of the table.

finish_horizontal then performs the line breaking of multi-paragraph cells (by producing a box from their lazy structure with a format_cell) and computes the horizontal position of each cell inside its column with position_horizontally.

2.4.Vertical positioning and final boxes

position_rows does the same for the rows: compute_heights collects heights (and depths and heights with respect to the baseline for anchored vertical alignments), blow_up distributes extra height according to cell-vpart, and table-valign fixes the vertical position of the table with respect to the baseline. For instance the alignment f, used when table-valign is not set, centers the table on the fraction bar height of the font.

Finally, finish calls cell_rep::finish for each cell, which wraps the content in a cell_box drawing background and borders, and assembles the cells into a table_box (or a composite_box for exotic alignments), wrapped in further cell_boxes for the table borders and paddings. var_finish instead produces one box per row for tables which may be broken across pages.

3.Remarks

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".