WeBWorK Problems

formatting tables

formatting tables

by Bruce Yoshiwara -
Number of replies: 4
What I'm trying to accomplish is to have a large rectangle partitioned into two rows and two columns, each of the four sub-rectangles filled with an answer rule. But I want text centered above each column, and more text to the left of each row.

The text outside the box represent lengths of sides of sub-rectangles. (This is an area model for multiplying binomials.)

In MSExcel I'd use a 3x3 set of contiguous cells and only draw the borders on the lower-right 2x2 cells.

How can I accomplish this in WeBWorK?

With the default WeBWorK table I could create a 3x3 table, leaving the (1,1) entry blank, but the appearance would confuse my developmental students.

Thanks.

Bruce Yoshiwara
In reply to Bruce Yoshiwara

Re: formatting tables

by Paul Pearson -
Dear Bruce,

I think what you want is provided by the "unionTables.pl" macro, which is automatically loaded when you load "PGunion.pl".

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"unionTables.pl", # or PGunion.pl
);

TEXT(beginproblem());

BEGIN_TEXT
\{
BeginTable().
Row([" ","${BCENTER}A${ECENTER}","${BCENTER}B${ECENTER}"]).
TableSpace(5,0).
Row(["1",ans_rule(10),ans_rule(10)]).
TableSpace(5,0).
Row(["2",ans_rule(10),ans_rule(10)]).
EndTable()
\}
END_TEXT

ANS( Real(11)->cmp() );
ANS( Real(12)->cmp() );
ANS( Real(21)->cmp() );
ANS( Real(22)->cmp() );

ENDDOCUMENT();
In reply to Paul Pearson

Re: formatting tables

by Bruce Yoshiwara -
Paul,

Thanks for the response.

The code you suggest does give a 2x2 array of answer rules, with row and column headings. But it's not quite what I really want--I'd like the student to see an actual rectangle partitioned into four sub-rectangles, with an ans_rule within each rectangle (with the dimensions of sub-rectangles labeled outside the figure).

I may resort to inserting a picture of a partitioned rectangle, with "answer A,", "answer B," etc. within the sub-rectangles and use the array you suggested for actual student input.
In reply to Bruce Yoshiwara

Re: formatting tables

by Paul Pearson -
Dear Bruce,

Neither html or latex like to make tables that way (they specify borders as part of the table as a whole, rather than defining them cell by cell). Here is a messy work around that is acceptable in html mode and minimally acceptable in tex mode (suggestions for improvement are welcome). It involves building everything up from scratch, rather than relying on macros.

Best Regards,

Paul

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);

TEXT(beginproblem());

$a11 = ans_rule(10);
$a12 = ans_rule(10);
$a21 = ans_rule(10);
$a22 = ans_rule(10);


TEXT(MODES(
TeX =>"
\[
\begin{array}{rcc}
& A & B \\
1 \cr 2 &
\multicolumn{2}{c}{
\begin{array}{|c|c|}
\hline
$a11 & $a12 \\
\hline
$a21 & $a22 \\
\hline
\end{array}
}
\end{array}
\]

",
HTML=>
"
<table border=~~"0~~">
<tr>
<td>&nbsp;</td>
<td align=~~"center~~">A</td>
<td align=~~"center~~">B</td>
</tr>
<tr>
<td>
1
<br><br>
2
</td>
<td colspan=~~"2~~">
<table border=~~"1~~" cellpadding=~~"10~~" cellspacing=~~"0~~">
<tr><td>$a11</td><td>$a12</td></tr>
<tr><td>$a21</td><td>$a22</td></tr>
</table>
</td>
</tr>
</table>
"
));


ANS( Real(11)->cmp() );
ANS( Real(12)->cmp() );
ANS( Real(21)->cmp() );
ANS( Real(22)->cmp() );


ENDDOCUMENT();
In reply to Paul Pearson

Re: formatting tables

by Bruce Yoshiwara -
Paul,

I don't actually understand the code, but pasting the HTML part works beautifully.

Thanks!

Bruce