There are two ways to create tables using existing WebWork code: basic tables (that load with PGstandard.pl) and slightly more advanced tables (provided by the unionTables.pl macro):
https://github.com/openwebwork/pg/blob/master/macros/unionTables.pl
Example 3 on this page
http://webwork.maa.org/wiki/Tables
uses the unionTables.pl macro, as do several examples on
http://webwork.maa.org/wiki/GraphsInTables
I strongly encourage you to use one of the two existing ways to make tables in WebWork. If neither of the two ways to create tables in WebWork meets your needs, you could define a display mode dependent variable that contains the table as follows.
$a = random(2,9,1);
if ($displayMode eq 'TeX') {
$mytable = "\[ \begin{array}{r} $a \end{array} \]";
} else { # html mode
$mytable = "<center><table><tr><td> $a </td></tr></table></center>";
}
BEGIN_TEXT
$mytable
END_TEXT
Best regards,
Paul Pearson