DocumentTools - Maple Programming Help

Home : Support : Online Help : Programming : Document Tools : DocumentTools/Tabulate

DocumentTools

 Tabulate
 Insert a worksheet Table from a Matrix, Vector, Array, DataFrame, list, or list of lists

 Calling Sequence Tabulate( M, opts )

Parameters

 M - {Array,Matrix,Vector,DataFrame,list,list(list)} opts - (optional) ; one or more keyword options as described below

Options

 • alignment : identical(left,right,center):=center ; The horizontal alignment of the Table in the worksheet. The default value is center.
 • color : {list(nonnegint),symbol,string,appliable}:=[0,0,0] ; The foreground color for text. The passed value can be either a specified color acceptable to ColorTools:-Color, or a procedure which returns such. A list of nonnegative integers is interpreted as RGB values in a 24bit 3-channel color space. In the case of a supplied procedure the passed arguments will be M, i, j for the cell in row i and column j. The default value is [0,0,0] which corresponds to black.
 • exterior identical(all,none):=all ; Indicates how exterior borders are shown.
 • fillcolor {list(nonnegint),symbol,string,appliable}:=[255,255,255] ; The background fill color for the Table cells. The passed value can be either a specified color acceptable to ColorTools:-Color, or a procedure which returns such. A list of nonnegative integers is interpreted as RGB values in a 24bit 3-channel color space. In the case of a supplied procedure the passed arguments will be M, i, j for the cell in row i and column j. If the first argument to Tabulate is not a DataFrame then the default value for fillcolor is [255,255,255] which corresponds to white. If the first argument to Tabulate is a DataFrame then the default value for fillcolor is a procedure which returns [210,230,255] for the first column or row, and [255,255,235] otherwise.
 • interior identical(all,none):=all ; Indicates how internal borders are shown.
 • plotcomponents truefalse ; Indicates whether plots are inserted within Plot Components. The default is false. When this option is false plot entries that are not part of expression sequences are inlined within individual Table cells.
 • typesetting : identical(standard,extended); Specifies the typesetting level. By default the current value returned by interface(typesetting) is used.
 • weights {list(nonnegint),Vector(nonnegint)} ; Relative weights for the Table's columns' widths. By default all columns have equal weight.
 • width : And(realcons,nonnegative):=100.0 ; Indicates the displayed width of the Table as a percentage of the worksheet's width in the case of option widthmode=percentage, or as the number or pixels in the case that option widthmode=pixels. The default is 100% of the displayed worksheet's width.
 • widthmode : identical(percentage,pixels):=percentage ; Whether the width option's value is interpreted as a percentage of the worksheet's width or as a number of pixels.

Description

 • The Tabulate command constructs and inserts a worksheet Table from a Matrix, Vector, one or two dimensional Array, DataFrame, list, or list of lists.
 • The return value of the command is the identity of the inserted parent Table, as a string. The display of the returned value can be suppressed by terminating the statement with a full colon.
 • Calls to the Tabulate command cannot be nested within each other.
 • Expressions are inserted as typeset 2D Math, and can be operated upon using right-click context-sensitive menu actions.
 • The inserted Tables will be removed by the main menu action Edit->Remove Output. Pasted copies of the inserted Tables are not removed.
 • This command inserts the assembly of Tables and Embedded Components into the worksheet using the InsertContent facility. The inserted content is placed after any usual output of the Execution Group in which this command is called. Each Execution Group allows for only one inserted result to exist at any given time. Multiple calls to commands which utilize the InsertContent facility made within the same Execution Group will result in each successive inserted assembly replacing any assembly inserted earlier for that Execution Group.

Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}\right):$

By default the inserted Table takes 100% of the width of the worksheet.

 > $\mathrm{Tabulate}\left(\left[a,b,c,d\right]\right):$

 $a$ $b$ $c$ $d$

In the next example the width of the Table is 50% of the width of the worksheet. That width ratio is maintained when the worksheet is maximized or manually resized.

 > $\mathrm{Tabulate}\left(\left[a,b,c,d\right],\mathrm{width}=50\right):$

 $a$ $b$ $c$ $d$

Column Vectors produce a Table with entries stacked vertically.

 > $\mathrm{Tabulate}\left(\mathrm{Vector}[\mathrm{column}]\left(\left[a,b,c,d\right]\right),\mathrm{width}=20\right):$

 $a$ $b$ $c$ $d$

The initial width can also be specified as pixels, under default zoom. In this case the Table will zoom along with the worksheet, under magnification.

 > $M≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(6,2\right)$
 ${M}{≔}\left[\begin{array}{rr}{-}{32}& {99}\\ {-}{74}& {29}\\ {-}{4}& {44}\\ {27}& {92}\\ {8}& {-}{31}\\ {69}& {67}\end{array}\right]$ (1)
 > $\mathrm{Tabulate}\left(M,\mathrm{widthmode}=\mathrm{pixels},\mathrm{width}=100\right):$

 $-32$ $99$ $-74$ $29$ $-4$ $44$ $27$ $92$ $8$ $-31$ $69$ $67$

2D and 3D plot entries are inlined by default.

 > $A≔\left[\mathrm{plot}\left(\frac{\mathrm{sin}\left(x\right)}{x}\right),{\sum }_{i=1}^{N}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}f\left(i\right),\mathrm{plot3d}\left({y}^{2}\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},y=-2..2\right)\right]:$
 > $\mathrm{Tabulate}\left(A,\mathrm{width}=60\right):$

 ${\sum }_{i=1}^{N}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}f\left(i\right)$

Plot entries can be inserted optionally within Plot Components, as opposed to being inlined.

 > $\mathrm{Tabulate}\left(A,\mathrm{width}=60,\mathrm{plotcomponents}\right):$

 ${\sum }_{i=1}^{N}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}f\left(i\right)$

The interior or exterior Table borders can optionally be hidden.

 > $\mathrm{Tabulate}\left(M,\mathrm{widthmode}=\mathrm{pixels},\mathrm{width}=100,\mathrm{exterior}=\mathrm{none}\right):$

 $-32$ $99$ $-74$ $29$ $-4$ $44$ $27$ $92$ $8$ $-31$ $69$ $67$

 > $\mathrm{Tabulate}\left(A,\mathrm{width}=60,\mathrm{interior}=\mathrm{none}\right):$

 ${\sum }_{i=1}^{N}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}f\left(i\right)$

The fillcolor option can be used to specify a background fill color, including the case of 3D plot entries.

 > $\mathrm{Tabulate}\left(\left[\mathrm{plot3d}\left({y}^{2}\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},y=-2..2,\mathrm{axis}=\left[\mathrm{color}=\mathrm{cyan}\right],\mathrm{orientation}=\left[55,75,0\right]\right)\right],\mathrm{fillcolor}="black",\mathrm{width}=400,\mathrm{widthmode}=\mathrm{pixels}\right):$

The color option can be used to specify a foreground color.

 > $\mathrm{Tabulate}\left(\left["Example text."\right],\mathrm{color}=\mathrm{red},\mathrm{fillcolor}="LightYellow",\mathrm{width}=30\right):$

 Example text.

 > $\mathrm{Tabulate}\left(\left["Example text."\right],\mathrm{color}="#FF0000",\mathrm{fillcolor}="LightYellow",\mathrm{width}=30\right):$

 Example text.

 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(3,4\right):$$\mathrm{header}≔⟨a|b|c|d⟩:$
 > $\mathrm{Tabulate}\left(⟨\mathrm{header},A⟩,\mathrm{width}=40,\mathrm{fillcolor}=\left(\left(T,i,\mathrm{jj}\right)→\mathrm{if}\left(i=1,\mathrm{cyan},\mathrm{white}\right)\right)\right):$

 $a$ $b$ $c$ $d$ $-38$ $33$ $57$ $-76$ $-18$ $-98$ $27$ $-72$ $87$ $-77$ $-93$ $-2$

 > $\mathrm{Tabulate}\left(A,\mathrm{width}=40,\mathrm{fillcolor}=\left(\left(T,i,j\right)→\mathrm{if}\left(\mathrm{irem}\left(j,2\right)=1,\mathrm{cyan},\mathrm{white}\right)\right)\right):$

 $-38$ $33$ $57$ $-76$ $-18$ $-98$ $27$ $-72$ $87$ $-77$ $-93$ $-2$

 > $P≔\mathrm{ColorTools}:-\mathrm{GetPalette}\left("css"\right):$$T≔\mathrm{table}\left(\left[\mathrm{seq}\left(\mathrm{ColorDescription}\left(c\right)=c,c=\left[{P}_{[]}\right]\right),""=\mathrm{ColorTools}:-\mathrm{Color}\left("White"\right)\right]\right):$$M≔{\mathrm{ArrayTools}:-\mathrm{Reshape}\left(\mathrm{Vector}\left(\left[\mathrm{indices}\left(T,\mathrm{nolist}\right),\mathrm{seq}\left("",i=1..3\cdot 6-\mathrm{numelems}\left(T\right)\right)\right]\right),\left[6,3\right]\right)}^{\mathrm{%T}}$
 ${M}{≔}\left[\begin{array}{cccccc}{"Blue"}& {"Yellow"}& {"Navy"}& {"Red"}& {"Aqua"}& {""}\\ {"Gray"}& {"Maroon"}& {"Black"}& {"Green"}& {"Olive"}& {"Orange"}\\ {"Teal"}& {"Purple"}& {"Silver"}& {"Fuchsia"}& {"Lime"}& {"White"}\end{array}\right]$ (2)
 > $\mathrm{Tabulate}\left(M,\mathrm{width}=60,\mathrm{color}=\left(\left(M,i,j\right)→\mathrm{if}\left(0.4<\mathrm{Luma}\left({T}_{{M}_{i,j}}\right),"Black",\left[240,240,240\right]\right)\right),\mathrm{fillcolor}=\left(\left(M,i,j\right)→\mathrm{ToRGB24}\left({T}_{{M}_{i,j}}\right)\right)\right):$

 Blue Yellow Navy Red Aqua Gray Maroon Black Green Olive Orange Teal Purple Silver Fuchsia Lime White

One additional level of nested lists is supported. Note that the middle entry in the following example is represented with an inner Table.

 > $L≔\left[\left["Some text",\left[{y}^{2}\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},y=-2..2\right],\mathrm{plot3d}\left({y}^{2}\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},y=-2..2\right)\right]\right]:$
 > $\mathrm{Tabulate}\left(L\right):$

Some text

 ${y}^{2}\mathrm{sin}\left(x\right)$ $x=-\mathrm{\pi }..\mathrm{\pi }$ $y=-2..2$

The Table can be inserted as left-aligned in the worksheet. The relative widths of the Table columns can be specified using the weights option.

 > \mathrm{Tabulate}\left(L,\mathrm{width}=60,\mathrm{alignment}=\mathrm{left},\mathrm{weights}=\left[3,3,7\right]\right):

Some text

 ${y}^{2}\mathrm{sin}\left(x\right)$ $x=-\mathrm{\pi }..\mathrm{\pi }$ $y=-2..2$

The level of typesetting or expression entries can be forced.

 > $\mathrm{Tabulate}\left(\left[\mathrm{π},\mathrm{Γ},\sqrt{2},\frac{ⅆ}{ⅆx}f\left(x\right),\mathrm{BesselJ}\left(0,x\right)\right],\mathrm{width}=50,\mathrm{typesetting}=\mathrm{standard}\right):$

 $\mathrm{\pi }$ $\mathrm{GAMMA}$ $\sqrt{2}$ $\frac{ⅆ}{ⅆx}f\left(x\right)$ $\mathrm{BesselJ}\left(0,x\right)$

 > $\mathrm{Tabulate}\left(\left[\mathrm{π},\mathrm{Γ},\sqrt{2},\frac{ⅆ}{ⅆx}f\left(x\right),\mathrm{BesselJ}\left(0,x\right)\right],\mathrm{width}=40,\mathrm{typesetting}=\mathrm{extended}\right):$

 $\mathrm{\pi }$ $\mathrm{\Gamma }$ $\sqrt{2}$ $f\prime \left(x\right)$ ${J}_{0}\left(x\right)$

The fillcolor has a different default for a DataFrame, which can be overridden.

 > $\mathrm{genus}≔⟨"Rubus","Vitis","Fragaria"⟩:$$\mathrm{energy}≔⟨220,288,136⟩:$$\mathrm{carbohydrates}≔⟨11.94,18.1,7.68⟩:$$\mathrm{total_tons}≔⟨543421,58500118,4594539⟩:$$\mathrm{top_producer}≔⟨\mathrm{Russia},\mathrm{China},\mathrm{USA}⟩:$$\mathrm{DF}≔\mathrm{DataFrame}\left(⟨\mathrm{energy}|\mathrm{carbohydrates}|\mathrm{total_tons}|\mathrm{top_producer}|\mathrm{genus}⟩,\mathrm{columns}=\left[\mathrm{Energy},\mathrm{Carbohydrates},\mathrm{Total Tons},\mathrm{Top Producer},\mathrm{Genus}\right],\mathrm{rows}=\left[\mathrm{Raspberry},\mathrm{Grape},\mathrm{Strawberry}\right],\mathrm{datatypes}=\left[\mathrm{integer},\mathrm{float},\mathrm{integer},\mathrm{anything},\mathrm{string}\right]\right)$
 ${\mathrm{DF}}{≔}\left[\begin{array}{cccccc}{}& {\mathrm{Energy}}& {\mathrm{Carbohydrates}}& {\mathrm{Total Tons}}& {\mathrm{Top Producer}}& {\mathrm{Genus}}\\ {\mathrm{Raspberry}}& {220}& {11.9400000000000}& {543421}& {\mathrm{Russia}}& {"Rubus"}\\ {\mathrm{Grape}}& {288}& {18.1000000000000}& {58500118}& {\mathrm{China}}& {"Vitis"}\\ {\mathrm{Strawberry}}& {136}& {7.68000000000000}& {4594539}& {\mathrm{USA}}& {"Fragaria"}\end{array}\right]$ (3)
 > $\mathrm{Tabulate}\left(\mathrm{DF},\mathrm{width}=600,\mathrm{widthmode}=\mathrm{pixels}\right):$

 Energy Carbohydrates Total Tons Top Producer Genus Raspberry $220$ $11.94$ $543421$ $\mathrm{Russia}$ Rubus Grape $288$ $18.1$ $58500118$ $\mathrm{China}$ Vitis Strawberry $136$ $7.68$ $4594539$ $\mathrm{USA}$ Fragaria

 > $\mathrm{lens}≔\left[4+\mathrm{max}\left(\mathrm{op}\left(\mathrm{~}[\mathrm{length}]\left(\mathrm{RowLabels}\left(\mathrm{DF}\right)\right)\right)\right),\mathrm{~}[:-\mathrm{+}]\left(4,\mathrm{ },\mathrm{op}\left(\mathrm{~}[\mathrm{length}]\left(\mathrm{ColumnLabels}\left(\mathrm{DF}\right)\right)\right)\right)\right]:$
 > $\mathrm{Tabulate}\left(\mathrm{DF},\mathrm{width}=\mathrm{add}\left(\mathrm{lens}\right)\cdot 6,\mathrm{widthmode}=\mathrm{pixels},\mathrm{weights}=\mathrm{lens},\mathrm{fillcolor}=\left(\left(M,i,j\right)→\mathrm{if}\left(i=1\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}j\ne 1,"LightBlue",\mathrm{if}\left(j=1\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}i\ne 1,"LightGreen","White"\right)\right)\right)\right):$

 Energy Carbohydrates Total Tons Top Producer Genus Raspberry $220$ $11.94$ $543421$ $\mathrm{Russia}$ Rubus Grape $288$ $18.1$ $58500118$ $\mathrm{China}$ Vitis Strawberry $136$ $7.68$ $4594539$ $\mathrm{USA}$ Fragaria

The Tabulate command provides an alternative to plots:-display as a mechanism for displaying Arrays of plots in a tabular form. In particular it provides the additonal functionality to specify the visibility of Table borders and the Table dimensions and alignment.

 > $A≔\mathrm{Array}\left(\left[\left[\mathrm{plot}\left(\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},\mathrm{size}=\left[200,200\right]\right),\mathrm{plot}\left(\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},\mathrm{size}=\left[200,200\right],\mathrm{scaling}=\mathrm{constrained}\right)\right],\left[\mathrm{plot}\left(\mathrm{cos}\left(x\right),x=-\mathrm{π}..\mathrm{π},\mathrm{size}=\left[200,200\right]\right),\mathrm{plot}\left(\mathrm{cos}\left(x\right),x=-\mathrm{π}..\mathrm{π},\mathrm{size}=\left[200,200\right],\mathrm{scaling}=\mathrm{constrained}\right)\right]\right]\right):$
 > $\mathrm{plots}:-\mathrm{display}\left(A\right)$

 > $\mathrm{Tabulate}\left(A,\mathrm{width}=700,\mathrm{widthmode}=\mathrm{pixels},\mathrm{interior}=\mathrm{none}\right):$

The return value of the command is the identity of the inserted Table and this can be used to modify the Table after insertion.

 > $A≔\mathrm{Array}\left(\left[\mathrm{plot}\left(\mathrm{sin}\left(x\right),x=-\mathrm{π}..\mathrm{π},\mathrm{size}=\left[300,200\right],\mathrm{scaling}=\mathrm{constrained}\right),\mathrm{plot}\left(\mathrm{cos}\left(x\right),x=-\mathrm{π}..\mathrm{π},\mathrm{size}=\left[300,200\right],\mathrm{scaling}=\mathrm{constrained}\right)\right]\right):$
 > $\mathrm{Tabulate}\left(A,\mathrm{width}=700,\mathrm{widthmode}=\mathrm{pixels}\right):$

 > $\mathrm{str1}≔\mathrm{Tabulate}\left(A,\mathrm{width}=700,\mathrm{widthmode}=\mathrm{pixels}\right):$

 > $\mathrm{str1}$
 ${"Tabulate21"}$ (4)
 > $\mathrm{SetProperty}\left(\mathrm{str1},\mathrm{exterior},\mathrm{none}\right);$$\mathrm{SetProperty}\left(\mathrm{str1},\mathrm{interior},\mathrm{none}\right)$
 > 

Compatibility

 • The DocumentTools[Tabulate] command was introduced in Maple 2015.