Documentation for the Package WriteTable.m

1. Introduction and Purpose

The Mathematica package WriteTable.m outputs a matrix as a table in TEX, tab-delimited ASCII or HTML.  The table format used for the TEX option also works with LATEX.  Tab-delimited ASCII is useful if it is desired to input the table to a spreadsheet or other statistical program.

Usually the entries in the matrix are numbers but character strings could also be used provided that all matrix entries are character strings.  Optional column and row headings may be character strings even with a numeric matrix.

Another package, TeXTableForm.m, written by Matthias Schunter is also available on MathSource (0204-578).  This package is limited to LATEX and is not compatible with TEX.

It should also be noted that the built-in Mathematica function, TableForm, can also be used to construct beautiful tables in Mathematica and these tables may be cut and pasted into documents in other programs such as Microsoft Word.  However, in this case the table will be treated as picture.

In §2, on basic usage, it is shown how to create three output files which illustrate the capabilities of the package WriteTable.m:  table.tex, table.txt and table.html.  In §3, we shown how, using the helper function MergeMatricies a more advanced table which entries given as a pair of numbers may be created.  The output from this is the file advtable.tex.

Basic Usage

The principal function provided in the package is WriteTable.  A helper function MergeMatricies can be used to create tables in which each entry is comprised of a pair of numbers.  In the examples below you will need to change the path and filename.

<< c:/math/2002/WriteTable.m

?WriteTable

Here is the data we will use,

x = {{0.050000000000000044`, 0.050000000000000044`, 
            0.050000000000000044`, 
            0.050000000000000044`}, {0.24504981907301948`, 
            0.185976961464851`, 0.1458451881494529`, 
            0.12415378409575828`}, {0.6043230508982721`, 0.4440198687642706`, 
            0.32132829525995854`, 0.2533175736476483`}, {0.8886265130389104`, 
            0.7294826943955453`, 0.5503102896071468`, 
            0.4310496464842428`}, {0.9851459097536082`, 0.9136034077051525`, 
            0.7632754091112183`, 0.6242572587873121`}, {0.9991219812563729`, 
            0.9827985632754207`, 0.9044464966242792`, 
            0.7901854710362064`}, {0.9999778059845772`, 0.9979303885141685`, 
            0.9711351124209204`, 0.9027615736665693`}, {0.999999764874356`, 
            0.999852348748329`, 0.9935800143908071`, 
            0.9630984737567984`}, {0.9999999989685334`, 0.9999938279629408`, 
            0.9989601572292689`, 0.9886431476578216`}};

and the table has row names,

rowHeadings = PaddedForm[#, {4, 3}] & /@ 
          Range[0, 2, 0.25];

and column names,

\(\(tablecols = 
        Prepend[{"\phi=0.00", \ "\phi=0.25", \ "\phi=0.50", "\phi=0.75"}, "\delta"];\)\)

and now we can output a table with column and row headings.  See table.pdf for what it looks like after processing with TEX.

WriteTable["c:/math/2002/misc/WriteTable/output/table.tex", x, 
      ColumnNames -> tablecols, 
      PrependColumn -> rowHeadings]

Here is the same table as tab-delimited ascii and html respectively,

WriteTable["c:/math/2002/misc/WriteTable/output/table.txt", x, 
      ColumnNames -> tablecols, PrependColumn -> rowHeadings, 
      OutputType -> "TXT"]

WriteTable["c:/math/2002/misc/WriteTable/output/table.html", x, 
      ColumnNames -> tablecols, PrependColumn -> rowHeadings, 
      OutputType -> "HTML"]

A More Complex Example

y = {{0.050000000000000044`, 0.050000000000000044`, 
            0.050000000000000044`, 
            0.050000000000000044`}, {0.30595221146027873`, 
            0.22556349388932595`, 0.1696606176835157`, 
            0.13513624518106848`}, {0.7356984495150937`, 0.5547923145516297`, 
            0.3950576493880228`, 0.28773395899954535`}, {0.961439159159245`, 
            0.8482824269187758`, 0.6639200271595259`, 
            0.49297956875222304`}, {0.9981645163344435`, 0.9725969907736207`, 
            0.8670452255601622`, 0.7001457841738437`}, {0.9999735725068861`, 
            0.997536184859261`, 0.9642177149616319`, 
            0.8570678607138427`}, {0.9999998891324086`, 0.9998934856868291`, 
            0.9936348186350793`, 0.9462635763556202`}, {0.9999999998671919`, 
            0.9999978295953903`, 0.9992650742586402`, 
            0.9843042743804116`}, {0.9999999999999551`, 0.9999999794053704`, 
            0.9999455638615068`, 0.996475213072505`}};

xy = MergeMatricies[x, y]

WriteTable["c:/math/2002/misc/WriteTable/output/advtable.tex", xy, 
      NumDecimals -> False, ColumnNames -> tablecols, 
      PrependColumn -> rowHeadings]

WriteTable["c:/math/2002/misc/WriteTable/output/advtable.html", xy, 
      NumDecimals -> False, ColumnNames -> tablecols, 
      PrependColumn -> rowHeadings, OutputType -> "HTML"]

Creating Beautiful Tables with TableForm

rh = StyleForm[#, FontFamily -> "Helvetica", 
            FontColor -> RGBColor[0, 0, 1]] & /@ 
        rowHeadings

ch = StyleForm[#, FontFamily -> "Helvetica", 
            FontColor -> 
              RGBColor[0, 0, 
                1]] & /@ {"ϕ=0.00",  "ϕ=0.25",  "\
ϕ=0.50", "ϕ=0.75"}

TableForm[
      Map[StyleForm[#, FontFamily -> "Helvetica"] &, xy, {2}], 
      TableHeadings -> {rh, ch}]