WeBWorK Main Forum

Tables and Hard Copy

by joel robbin -
Number of replies: 2
The following code generates a nice table for a matching problem,
but runs into the next column when generating hardcopy.
Is there any way to have WW make a narrower table
(e.g. insert line breaks before then) or turn of the two column
format?

\{begintable(3)\}
\{row( ans_rule(3),
"(1) $$y = f(x + a) + b$$ ",
"(A) Translate left $a units, then translate down$b units.")
\}

\{row( ans_rule(3),
"(2) $$y = f(x + b) + a$$",
"(B) Translate left $b units, then translate up$a units.")
\}

etc

\{endtable()\}

Re: Tables and Hard Copy

by Davide Cervone -
You can use $END_TWO_COLUMN to turn off the double-column mode, and$BEGIN_TWO_COLUMN to start it up again. I'm not sure exactly what will happen if you use this in a problem in the middle of a problem set, but you can give it a try.

It is not easy to get a line break in a table in TeX. One way to do it is to use a \vbox either of a fixed width (and let TeX do the line breaking), or stack your lines in \hbox's yourself. If course, doing that in WeBWorK is a bit subtle, and should not be done by entering raw TeX commands. You would need to write a macro that handles the details properly in the different modes available to WeBWorK.

Something like the following (untested) code might work:

    sub cellLines {
my @lines = @_; my ($pre,$post) = ('','');
if ($displayMode eq 'TeX') { foreach my$line (@lines) {$line = '\hbox{\strut '.$line.'}'};
$pre = '\vtop{';$post = '}';
}
return $pre.join(" ",@lines).$post;
}

and then you use it as
    BEGIN_TEXT
\{begintable(3)\}
\{row(
ans_rule(3),
"(1) $$y = f(x + a) + b$$ ",
cellLines("(A) Translate left $a units,", "then translate down$b units."),
)\}
\{row(
ans_rule(3),
"(2) $$y = f(x + b) + a$$",
cellLines("(B) Translate left $b units,", "then translate up$a units."),
)\}
.
.
.
\{endtable()\}
END_TEXT

The cellLines() command will make the strings into a single line when displayed on screen, but into separate lines in the hardcopy file. That might be what you are looking for. You might also want to try
        $pre = '$\vcenter{'; $post = '}$';

instead to get a centered cell rather than one that is aligned along the top. Use a plain \vbox to get one aligned along the bottom.

The cellLines definition could be put into a separate .pl file in the course templates/macros directory, and use loadMacros() to load it.

Hope that helps.

Davide
OOPS! I should have said $BEGIN_ONE_COLUMN and$END_ONE_COLUMN rather than $END_TWO_COLUMN and$BEGIN_TWO_COLUMN. Sorry about that.