From WeBWorK_wiki
Revision as of 15:13, 18 February 2010 by Pearson (talk | contribs) (New page: <h2>Aligned Answer Blanks</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This PG code s...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Aligned Answer Blanks

This PG code shows how to align answer blanks and restrict the type of student answer allowed.

Problem Techniques Index

PG problem file Explanation

Initialization: We need to include the macro file for aligning the answer blanks.


$f1 = Formula("sin(pi/6)");
$f2 = Formula("sin(pi/4)");
$f3 = Formula("sin(pi/3)");
$f4 = Formula("sin(pi/2)");
$f5 = Formula("sin(pi)");
$f6 = Formula("sin(2pi)");


$al = new_aligned_list(ans_rule_len=>10, numbered=>1, tex_spacing=>"3pt");
"\($f1\)", Real($f1->eval)->cmp,
"\($f2\)", Real($f2->eval)->cmp,
"\($f3\)", Real($f3->eval)->cmp,
"\($f4\)", Real($f4->eval)->cmp,
"\($f5\)", Real($f5->eval)->cmp,
"\($f6\)", Real($f6->eval)->cmp,

Setup: We disable all functions, and then enable square root.

The options for aligned list are vertical alignment, horizontal alignment, cellspacing, tex spacing (which must include units of measure, such as "pt"), whether or not the list is numbered, whether there is a column of equals signs, and the length of each answer rule. The defaults and other options are given below.

  • valign=>"MIDDLE" or TOP or BOTTOM
  • align=>"RIGHT" or LEFT or CENTER
  • spacing=>"5"
  • tex_spacing=>"0pt", where 1pt = 1/72in. 3pt is usually good.
  • numbered=>"0" for no numbering, or 1 for numbering
  • equals=>"1" for a column of equals signs, 0 to omit them
  • ans_rule_len=>"10"

Find the sine of each of the following angles.
Remark: Your answer cannot contain trigonometric functions;
it must be an arithmetic expression or number.

Main Text: It's a good idea to explain to students that the type of answers allowed are restricted.

$showPartialCorrectAnswers = 1;
ANS( $al->correct_ans );


Answer Evaluation: As expected.

Problem Techniques Index