/* ** Program ExTable.Ox ** ** Purpose: ** Example creating LaTeX tables ** ** Version: ** 1 Based on VaRisk.ox ** ** Author: ** Charles Bos ** Patrick Houweling ** ** Date: ** 16/6/2001 changed by Patrick to deal with improved PrintMat function ** 16/4/2004 added simpler printtex interface ** 2/2/2005 added support for printing parentheses in format */ #include #include main() { decl i, aPrFmt, arLabs, acLabs, mX, nDim, mY, fh, ir; // Get the data from the database nDim= 3; mX= rann(nDim, 1000); mY= meanr(mX)~varr(mX)~limits(mX')[:1][]'; aPrFmt= acLabs= new array[nDim]; for (i= 0; i < nDim; ++i) { aPrFmt[i]= "%7.3f"; acLabs[i]= sprint("$R(", i, ")$"); } arLabs= {"$\\mu$", "$\\sigma^2$", "min", "max"}; // Print the table to a file, with one line before and after the // table, two lines between the column headings and the table // itself, and with the LaTeX tabular environment included fh= fopen("table.out", "a"); PrintMatrix(fh, "extable", aPrFmt, acLabs, arLabs, mY', 1, 2, TRUE); fh= fclose(fh); // Print the table to screen PrintMatrix(0, "extable", aPrFmt, acLabs, arLabs, mY', 1, 2, TRUE); // Print the table to screen, using simpler printtex format println ("\nUsing simpler printtex format"); printtex("extable", "%cf", aPrFmt, "%c", acLabs, "%r", arLabs, mY'); print("extable", "%cf", aPrFmt, "%c", acLabs, "%r", arLabs, mY'); // Print the table to screen, using simpler printtex format, with parentheses println ("\nUsing parentheses in format"); aPrFmt= {"%7.3f", " (%.2f)", "%7.3f", "%7.3f"}; printtex("extable", "%cf", aPrFmt, "%c", arLabs, "%r", acLabs, mY); print("extable", "%cf", aPrFmt, "%c", arLabs, "%r", acLabs, mY); // Save the table for later use println ("\nSaving table.tab"); ir= savetab("table.tab", arLabs, acLabs, mY'); // Add extra column to the table println ("\nAdd column to table.tab"); mX= rann(1, 1000); mY= meanr(mX)|varr(mX)|limits(mX')[:1][]; ir= savetab("table.tab", arLabs, "$R(3)$", mY, "a"); ir= loadtab("table.tab", &arLabs, &acLabs, &mY); print ("extable", "%r", arLabs, "%c", acLabs, mY); // Add extra row println ("\nAdd row to table.tab"); ir= savetab("table.tab", "LL", acLabs, ones(1, 4), "a"); ir= loadtab("table.tab", &arLabs, &acLabs, &mY); print ("extable", "%r", arLabs, "%c", acLabs, mY); }