Topic: Reporting

Online Help


Tables (Pro only)


This feature is available only in Calcpad VM Pro 8.

The table(M; nhrows; nhcols) function displays the matrix M as a table, with nhrows header rows and nhcols header columns (1 and 0 by default). The elements can be strings, numbers and values with units. The table is displayed in place of the equation. It is exported as a table to Word and LaTeX, and as a Markdown table in the text output. For example:

M = ["Section"; "Force, kN"; "Force, kN"; "η"|"Section"; "Fx"; "Fy"; "η"|"B1"; 12.5; 4.2; 0.62|"B2"; 18; 6.75; 0.88]
Table.Style = TableStyle.Rules
Table.MergeHeaders = 1
table(M; 2; 1)

Tables cannot be used in arithmetic operations, but you can apply the "+" and relational operators to their body cells, which must be strings. The other operand can be a string or another table of the same size. The headers are kept unchanged, and the result is a new table with the same headers. For example, if T = table(["Name"; "Grade"|"Anna"; "A"|"Ivan"; "B"]), then T + "!" appends "!" to the body cells "Anna", "A", "Ivan" and "B", and T ≡ "A" returns a table with the same header and a body of ones and zeros. If any body cell is a number, an error is returned.

Only the structural and data matrix functions accept tables. If they return a new matrix, it is a table with the same headers (transp swaps them). The in-place functions mfill, fill_row, fill_col, mresize, copy and add change the table itself, as they do for matrices, but mfill fills only the body and keeps the headers. sort_rows, sort_cols and their reverse versions sort only the body and keep the headers in place, so the result is still a table. order_rows and order_cols return the indexes of all rows or columns, the header ones first, so that extract_rows(T; order_rows(T; j)) is the same as sort_rows(T; j). mcount, mfind, msearch, hlookup and vlookup search only the body, but use and return the indexes of the whole table. The lookups can return header elements, e.g. vlookup(T; x; 2; 1) returns the row headers of the rows that have x in column 2. To get the data of a table T as a matrix, use val(T), and to join its elements into a text, use join(T; colsep; rowsep).

The appearance of tables is controlled by table options, whose names start with "Table.". They work as the plot options (see "Plot options"). An option remains in effect for all tables that follow, until it is changed. If you assign Auto to an option, it will be restored to its default. You can reset all options at once by calling Table.Reset(), and read the value of an option in expressions, e.g. s = Table.Style. The available options are listed below:

Option Description
Table.Style style of the borders and fills of the table, described below (TableStyle.Bordered by default);
Table.CellAlign alignment of the cells = Align.Left | Align.Center | Align.Right. You can specify one value for all columns or a vector with one value per column, e.g. [Align.Left; Auto; Align.Right]. The missing values and Auto align numbers to the right and text to the left;
Table.HeadAlign alignment of the header cells, specified as above. With Auto, the header rows are centered and the header columns are aligned as the other cells;
Table.MergeCells merges the cells from row i1, column j1 to row i2, column j2 = [i1; j1; i2; j2]. To merge several ranges, specify a matrix with four columns and one range per row. The merged cell shows the value of its top-left cell. The ranges are clipped to the table, and the ones that overlap previous ranges are skipped;
Table.MergeHeaders merges the adjacent header cells with equal text = 1 | 0. The cells are merged along the rows first, and then down the columns, where the cells below have the same width;
Table.CellColor text color of the cells;
Table.CellFill background color of the cells;
Table.AltColor text color of the alternate (even) rows;
Table.AltFill background color of the alternate (even) rows;
Table.HeadColor text color of the header cells;
Table.HeadFill background color of the header cells.

Colors are specified by name, e.g. Color.SteelBlue, or in hex format, e.g. "#4682B4". The following styles are available. The previews below show a table with one header row and one header column, created by table(M; 1; 1):

Bordered (default) - all cells have borders and the header cells are filled in gray.
Table.Style = TableStyle.Bordered
Rules - thick lines above and below the table and a thin line below the header, as in scientific publications.
Table.Style = TableStyle.Rules
Member N, kN M, kNm
B1 12.5 4.2
B2 18.0 6.8
B3 9.6 3.1
Member N, kN M, kNm
B1 12.5 4.2
B2 18.0 6.8
B3 9.6 3.1
Lines - horizontal lines between the rows.
Table.Style = TableStyle.Lines
Striped - horizontal lines, gray header rows and gray fill of the alternate rows.
Table.Style = TableStyle.Striped
Member N, kN M, kNm
B1 12.5 4.2
B2 18.0 6.8
B3 9.6 3.1
Member N, kN M, kNm
B1 12.5 4.2
B2 18.0 6.8
B3 9.6 3.1
Zebra - gray header rows and gray fill of the alternate rows, without lines.
Table.Style = TableStyle.Zebra
Boxed - a frame around the table and lines after the header rows and the header columns.
Table.Style = TableStyle.Boxed
Member N, kN M, kNm
B1 12.5 4.2
B2 18.0 6.8
B3 9.6 3.1
Member N, kN M, kNm
B1 12.5 4.2
B2 18.0 6.8
B3 9.6 3.1
Banner - dark header with white text, horizontal lines and gray fill of the alternate rows.
Table.Style = TableStyle.Banner

The styles use only shades of gray. You can apply other colors by the color options above. In the striped styles, the header columns are filled in a slightly darker gray. The text output shows only the alignment of the columns.