Command Reference : Working with Tables and Spreadsheets : Customizing Tables
  
Customizing Tables
 
Column Width and Row Height
Cell Formatting
Content Formatting
Justification and Indentation
Fonts
Background and Borders
Cell Annotation and Merging
EViews provides considerable control over the appearance of table objects, providing a variety of table procedures allowing you specify row heights and column widths, content formatting, justification, font face, size, and color, cell background color and borders. Cell merging and annotation are also supported.
Column Width and Row Height
We begin by noting that if the contents of a cell are wider or taller than the display width or height of the cell, part of the cell contents may not be visible. You may use the Table::setwidth and Table::setheight table procedures to change the dimensions of a column or row of table cells.
To change the column widths for a set of columns in a table, use the setwidth keyword followed by a column range specification in parentheses, and a desired width.
The column range should be either a single column number or letter (e.g., “5”, “E”), a colon delimited range of columns (from low to high, e.g., “3:5”, “C:E”), or the keyword “@ALL”. The width unit is computed from representative characters in the default font for the current table (the EViews table default font at the time the table was created), and corresponds roughly to a single character. Width values may be non-integer values with resolution up to 1/10 of a unit. The default width value for columns in an unmodified table is 10.
For example, both commands
tab1.setwidth(2) 12
tab1.setwidth(B) 12
set the width of column 2 to 12 width units, while the command
tab1.setwidth(2:10) 20
sets the widths for columns 2 through 10 to 20 width units. To set all of the column widths, use the “@ALL” keyword.
tab1.setwidth(@all) 20
Similarly, you may specify row heights using the setheight keyword, followed by a row specification in parentheses, and a desired row height.
Rows are specified either as a single row number (e.g., “5”), as a colon delimited range of rows (from low to high, e.g., “3:5”), or using the keyword “@ALL”. Row heights are given in height unit values, where height units are in character heights. The character height is given by the font-specific sum of the units above and below the baseline and the leading in the default font for the current table. Height values may be non-integer values with resolution up to 1/10 of a height unit. The default row height value is 1.
For example,
tab1.setheight(2) 1
sets the height of row 2 to match the table default font character height, while
tab1.setheight(2) 3.5
increases the row height to 3-1/2 character heights.
Similarly, the command:
tab1.setheight(2:7) 1.5
sets the heights for rows 2 through 7 to 1-1/2 character heights.
tab1.setheight(@all) 2
sets all row heights to twice the default height.
Earlier versions of EViews supported the setting of column widths using the setcolwidth command. This command, which is provided for backward compatibility, offers only a subset of the capabilities of Table::setwidth.
Cell Formatting
A host of cell characteristics may be set using table procedures. Each procedure is designed to work on individual cells, ranges of cells, or the entire table.
Content Formatting
Cell content formatting allows you to alter the appearance of the data in a table cell without changing the contents of the cell. Using the table proc Table::setformat, you may, for example, instruct EViews to change the format of a number to scientific or fixed decimal, or to display a date number in a different date format. These changes in display format do not alter the cell values.
To format the contents of table cells, simply follow the table name with a period and the setformat proc keyword, followed by a cell range specification in parentheses, and then a valid numeric or date format string. The cell range may be specified in a number of ways, including individual cells, cell rectangles, row or column ranges or the entire table. See Table::setformat for a description of cell range specification and numeric and date format string syntax.
For example, to set the format for the fifth column of a matrix to fixed 5-digit precision, you may provide the format specification:
tab1.setformat(e) f.5
To set a format for the cell in the third row of the fifth column to scientific notation with 5 digits of precision, specify the individual cell, as in:
tab1.setformat(3,e) e.5
tab1.setformat(e3) e.5
To specify the format for a rectangle of cells, specify the upper left and lower right cells in the rectangle. The following commands set cells in the same region to show 3-significant digits, with negative numbers in parentheses:
tab1.setformat(2,B,10,D) (g.3)
tab1.setformat(r2c2:r10c4) (g.3)
tab1.setformat(b2:d10) (g.3)
The rectangle of cells is delimited by row 2, column 2, and row 10, column 4.
Alternately you may provide a date format for the table cells. The command:
tab1.setformat(@all) "dd/MM/YY HH:MI:SS.SSS"
will display numeric values in the entire table using formatted date strings containing days followed by months, years, hours, minutes and seconds, to a resolution of thousandths of a second.
Note that changing the display format of a cell that contains a string will have no effect unless the cell is later changed to contain a numerical value.
Justification and Indentation
The cell justification and indentation control the position of the table cell contents within the table cell itself.
You may use the Table::setjust proc to position the cell contents in the cell. Simply use the setjust keyword, followed by a cell range specification in parentheses, and one or more keywords describing a vertical or horizontal position for the cell contents. You may use the keywords auto, left, right, and center to control horizontal positioning, and top, middle, and bottom to control vertical positioning. You may use the auto keyword to specify left justification for string cells and right justification for numeric cells.
For example,
tab1.setjust(@all) top left
sets the justification for all cells in the table to top left, while
tab1.setjust(2,B,10,D) center
horizontally centers the cell contents in the rectangle from B2 to D10, while leaving the vertical justification unchanged.
In addition, you may use Table::setindent to specify a left or right indentation from the edge of the cell for cells that are left or right justified, respectively. You should use the setindent keyword followed by a cell range in parentheses, and an indentation unit, specified in 1/5 of a width unit. Indentation is only relevant for non-center justified cells.
For example:
tab1.setjust(2,B,10,D) left
tab1.indent(2,B,10,D) 2
left-justifies, then indents the specified cells by 2/5 of a width unit from the left-hand side of the cell.
Alternatively,
tab2.setjust(@all) center
tab2.indent(@all) 3
will set the indentation for all cells in the table to 3/5 of a width unit, but this will have no effect on the center justified cells. If the cells are later modified to be left or right justified, the indentation will be used. If you subsequently issue the command
tab2.indent(@all) right
the cells will be indented 3/5 of a width unit from the right-hand edges.
Fonts
You may specify font face and characteristics, and the font color for table cells using the Table::setfont and Table::settextcolor table procs.
The setfont proc should be used to set the font face, size, boldface, italic, strikethrough and underline characteristics for table cells. You should provide a cell range specification, and one or more font arguments corresponding to font characteristics that you wish to modify. For example:
tab1.setfont(3,B,10,D) "Times New Roman" +u 8pt
changes the text in the specified cells to Times New Roman, 8 point, underline. Similarly,
tab1.setfont(4,B) -b +i -s
adds the italic to and removes boldface and strikethrough from the B4 cell.
To set the color of your text, use settextcolor with a cell range specification and a color specification. Color specifications may be provided using the @RGB settings, or using one of the EViews predefined colors keywords:
tab1.settextcolor(f2:g10) @rgb(255, 128, 0)
tab1.settextcolor(f2:g10) orange
sets the text color for the specified cells to orange. See Table::setfillcolor for a complete description of color specifications.
Background and Borders
You may set the background color for cells using the Table::setfillcolor table procedure. Specify the cell range and provide a color specification using @RGB settings or one of the predefined color keywords. The commands:
tab1.setfillcolor(R2C3:R3C6) ltgray
tab1.setfillcolor(2,C,3,F) @rgb(192, 192, 192)
both set the background color of the specified cells to light gray.
The Table::setlines table proc may be used to draw borders or lines around specified table cells. If a single cell is specified, you may draw borders around the cell or a double line through the center of the cell. If multiple columns or rows is selected, you may, in addition, add borders between cells.
Follow the name of the table object with a period, the setlines keyword, a cell range specification, and one or more line arguments describing the lines and borders you wish to draw. For example:
tab1.setlines(b2:d6) +a -h -v
first adds all borders (“a”) to the cells in the rectangle defined by B2 and D6, then removes the inner horizontal (“h”), and inner vertical (“v”) borders. The command
tab1.setlines(2,b) +o
adds borders to the outside (“o”), all four borders, of the B2 cell.
You may also use the setlines command to place double horizontal separator lines in the table. Enter the setlines keyword, followed by the name of the table, and a row number, both in parentheses. For example,
bestres.setlines(8) +d
places a separator line in the eighth row of the table BESTRES. The command:
bestres.setlines(8) -d
removes the double separator lines from all of the cells in the eighth row of the table.
Cell Annotation and Merging
Each cell in a table object is capable of containing a comment. Cell comments contain text that is hidden until the mouse cursor is placed over the cell containing the comment. Comments are useful for adding notes to a table without changing the appearance of the table.
To add a comment with the Table::comment table proc, follow the name of the table object with a period, a single cell identifier (in parentheses), and the comment text enclosed in double quotes. If no comment text is provided, a previously defined comment will be removed.
To add a comment “hello world” to the cell in the second row, fourth column, you may use the command:
tab1.comment(d2) "hello world"
To remove the comment simply repeat the command, omitting the text:
tab1.comment(d2)
In addition, EViews permits you to merge cells horizontally in a table object. To merge multiple cells in a row or to un-merge previously merged cells, you should use the Table::setmerge table proc. Enter the name of the table object, a period, followed by a cell range describing the cells in a single row that are to be merged.
If the first specified column is less than the last specified column (left specified before right), the cells in the row will be merged left to right, otherwise, the cells will be merged from right to left. The contents of the merged cell will be taken from the first cell in the merged region. If merging from left to right, the leftmost cell contents will be used; if merging from right to left, the rightmost cell contents will be displayed.
For example,
tab1.setmerge(a2:d2)
merges the cells in row 2, columns 1 to 4, from left to right, while
tab2.setmerge(d2:a2)
merges the cells in row 2, columns 2 to 5, from right to left. The cell display will use the leftmost cell in the first example, and the rightmost in the second.
If you specify a merge involving previously merged cells, EViews will unmerge all cells within the specified range. We may then unmerge cells by issuing the Table::setmerge command using any of the previously merged cells. The command:
tab2.setmerge(r2c4)
unmerges the previously merged cells.