WeBWorK Problems

DataTable display in hardcopy

DataTable display in hardcopy

by Steven Fiedler -
Number of replies: 3

I'm designing a problem that requires students to enter their data into a table. The problem and table both look fine in a browser but the table wraps in an unpleasant manner in the pdf hardcopy.  This issue could likely be resolved if the last couple columns were removed and put into a separate problem. However, it would be nice to find another option since the current format permits the student to see all of the data at once.  Below is a sanitized code example and a screenshot of the hardcopy is attached. I appreciate any thoughts.

DOCUMENT();

loadMacros(
'PGstandard.pl','PGML.pl','niceTables.pl','PGcourse.pl',);

$tab2 = DataTable(
 [
   [['Approx.',rowtop=>'1'],'Exact volume','Mass of grad.','Mass of','Density of'],
   [ 'sample','of ethanol','cylinder &','ethanol','ethanol'],
   [ ['volume (mL)',rowbottom=>'1'],'sample (mL)','ethanol sample (g)','sample (g)','(g/mL)'],
   [ [2,rowbottom=>'1'], ans_rule(1), ans_rule(1), ans_rule(1), ans_rule(1) ],
   [ [4,rowbottom=>'1'], ans_rule(1), ans_rule(1), ans_rule(1), ans_rule(1) ],
   [ [6,rowbottom=>'1'], ans_rule(1), ans_rule(1), ans_rule(1), ans_rule(1) ],
   [ [8,rowbottom=>'1'], ans_rule(1), ans_rule(1), ans_rule(1), ans_rule(1) ],
 ],
 align => '|c|c|c|c|c|',
);

BEGIN_PGML
 Complete the below table.

[$tab2]*
END_PGML

$ans=Real(1);
ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp);
ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp);
ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp);
ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp); ANS($ans->cmp);

ENDDOCUMENT();

Attachment Screenshot_2025-02-04_12-32-46.png
In reply to Steven Fiedler

Re: DataTable display in hardcopy

by Alex Jordan -

It looks like you are seeing how the table does not wrap at all, not that it wraps in a bad way. This is just how LaTeX tabulars work, usually. But you could make those title cells be "paragraph cells" with specified widths. I'll do that in the example pasted below.

Note that PGML.pl loads niceTables.pl, so you need not load niceTables.pl explicitly.

Also there is PGML markup for tables, which I will demonstrate.

Lastly, even constraining the widths on the header cells, you are using a two-column hardcopy theme. So there is just a limit on how much width you have to work with. It may end up that if you take the widest word from each header cell, there's just not enough space.


DOCUMENT();

loadMacros('PGstandard.pl','PGML.pl','PGcourse.pl');

BEGIN_PGML
Complete the below table.

[#
    [.Approx. sample volume.]{halign => '|p{0.16}|'}
    [.Exact volume of ethanol sample (mL).]{halign => 'p{0.16}|'}
    [.Mass of grad. cylinder & ethanol sample (g).]{halign => 'p{0.16}|'}
    [.Mass of ethanol sample (g).]{halign => 'p{0.16}|'}
    [.Density of ethanol (g/mL).]*{headerrow => 1, halign => 'p{0.16}|'}

    [.[`2`].]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]*

    [.[`4`].]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]*

    [.[`6`].]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]*

    [.[`8`].]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]
    [.[_]{$ans}.]

#]{align => '|*{5}{c|}', horizontalrules => 1, booktabs => 0}

END_PGML

ENDDOCUMENT();
In reply to Alex Jordan

Re: DataTable display in hardcopy

by Steven Fiedler -
Many thanks Alex. The problem is operational. 

I subsequently ran into a formatting issue using the sample problem guide for niceTables but it's a relatively minor consideration.  At some point, I may work up a MWE for that and submit it as a new question.
In reply to Steven Fiedler

Re: DataTable display in hardcopy

by Glenn Rice -

The link you gave is not a sample problem guide.  It is a unit test file.  The current sample problems can be accessed from the PG problem editor in webwork2.  There is a button above the code editor window for that.

I just did a lot of work on the sample problems in a pending pull request (see https://github.com/openwebwork/pg/pull/1152).  There are several problems that demonstrate the new PGML niceTables syntax.