Skip to main content

Columns

Labelling, aligning, sizing, hiding, moving, and combining columns.

Keisen’s column directives: columns-label, columns-align, columns-width, columns-hide, columns-move, and columns-combine.
Column directives
Function Effect
columns-label(..pairs) Named arguments map a column name to its label. Labelling the row-name column labels the stubhead.
columns-align(alignment, columns: auto) Sets alignment, direction-relative (start, end) or absolute. A name is held to the table; auto and a predicate filter the columns the table ends up with.
columns-width(widths) A dictionary of column name to length, fraction, or auto.
columns-hide(..columns) Removes columns from the table; they stay readable by predicates and formatters.
columns-move(..columns, before: none, after: none) Reorders columns relative to another column. The anchor names one column.
columns-combine(into, from, pattern, label: auto, hide-sources: true) Builds one column from several. pattern takes one argument per source, in from order.

columns-hide and columns-move take one column name per argument, and an array gives the names it holds. columns-hide(("units", "price")) says what columns-hide("units", "price") says. The before and after anchors of columns-move name one column each, so neither reads an array.

columns-combine receives the formatted content of its sources, not their raw values, which is what makes (estimate, error) => [#estimate (#error)] read the way it is written: each source keeps whatever its own format-* directive gave it. The combined column takes the place of the first of its sources, and the sources are hidden rather than dropped, so predicates and formatters can still read them; hide-sources: false shows them as well.

How a combined column lines up

Each value in a combined cell lines up with the same value in the other rows. A number lines up on its decimal separator, as it does in a numeric column. The text between two values is the glue: a comma, a bracket, or ±. The glue lines up with the glue at the same place in the other rows.

Keisen finds the values with a second call to the pattern. In this call, each source is a marker instead of formatted content. A marker is text, so a pattern that reads .text from a value also runs on a marker. The markers in the result show where each value goes, and the content between the markers is the glue. For (low, high) => [#low, #high], the cell is the value low, then a comma and a space as glue, then the value high.

A value can have one element around it, for example strong(low) or emph(low). That element stays on the value, and the width of the value is measured with it. A text(..) call with settings does not count as such an element, because keisen cannot compare its settings between rows.

Keisen then calls the pattern with the real values of each row, as it always does. If the split does not give the same content as this call, that cell is not lined up. The cell then shows the content of the pattern, at the edge of the column. This occurs when:

  • no value in the cell is a number, for example a combine of a first name and a last name;
  • a value is inside more than one element, for example box(strong(low)), or inside a text(..) call with settings;
  • the glue holds a line break or a paragraph break;
  • the pattern writes a value twice, or does not write one of its values;
  • the pattern gives a different result for some values, for example if error == [--] [#estimate] else [#estimate (#error)].

A cell also shows the content of the pattern when its column is narrower than the lined-up cell, so that the content can wrap.

A value that is not a number, such as a substituted gap, sits at the end of its box. The box is wide enough for the widest such value, so the glue after it does not move.

A combined column with one or more lined-up cells sits against the end edge, as a numeric column does. columns-align changes this edge, in either spelling. With the theme option decimal-align: false, keisen does not line up a combined column, and the column sits at the start edge. Keisen then does not call the pattern with markers. Use this option for a pattern that cannot take a marker, for example one that converts a value with float(value.text). A combined column cannot be summarised, because content has no total.

What columns-align reaches

Alignment is resolved once the table knows which columns it has, so a directive reads the same wherever it is written, and the last one written for a column wins.

The stub’s row-name column takes an alignment when columns-align names it, and so does any summary label beside it, so the column reads as one column. The stubhead follows it too while column-labels-align is auto, exactly as the other column labels do; a theme that sets that option wins over the column. A selector that filters rather than names never reaches the stub, because the stub leaves the column list; write the name out.

Four cases are reported rather than ignored, because in each the directive would do nothing:

  • A column the table does not carry, named either as a name or in an array of names. auto and a predicate filter rather than name, so matching nothing is silent.
  • A hidden column, whether columns-hide removed it or columns-combine hid it as a source.
  • A stub group or indent column. Only the row name is drawn as a cell: a group is a row label across the table, and an indent column sets a depth.
  • A stub that carries indentation, given anything but start. Indentation is leading space before the row name, and any other alignment absorbs it, so every level would sit flush against the same edge.

A stub is not decimal-aligned, so a stub of figures set against the end edge is ragged rather than lined up on the separator. It is formatted like any other column, but the decimal metric that pads a column against its separator is computed for the data columns alone. Keep such figures in a data column, and let the stub carry the row names, which is what a stub is for.

There is no columns-show, and the asymmetry is deliberate. Directives are the document’s own, so a column is shown by not hiding it; an unhide exists only to undo a sibling directive a few lines above, which is ceremony rather than a feature. A column named by no columns-hide is visible already.

Back to top