WeBWorK Problems

Multiple choice in tables and tables do not export well

Multiple choice in tables and tables do not export well

by Hedley Pinsent -
Number of replies: 3
When generating a hardcopy (pdf), the multiple choice in the tables go horizontal instead of vertical. Additionally tables, in general, extend across the adjacent column. Is there a way to not have two columns. Is there a way to control the text output so that the multiple choice is presented vertically?
In reply to Hedley Pinsent

Re: Multiple choice in tables and tables do not export well

by Arnold Pizer -
Hi  Hedley,

As for one column output, use 
TEXT($BEGIN_ONE_COLUMN); 
and  
TEXT($END_ONE_COLUMN);

If you do a search in the NPL for BEGIN_ONE_COLUMN  you will find a ton of examples, e.g. 

Rochester/setMatrices1Operations/ur_ma_1_3.pg:TEXT($BEGIN_ONE_COLUMN,beginproblem()) ;
Rochester/setMatrices1Operations/ur_ma_1_2a.pg:TEXT($BEGIN_ONE_COLUMN,beginproblem()) ;
Rochester/setMatrices1Operations/ur_ma_1_1a.pg:TEXT($BEGIN_ONE_COLUMN,beginproblem()) ;

I'm not sure about about having multiple choice presented vertically.

Arnie

In reply to Arnold Pizer

Re: Multiple choice in tables and tables do not export well

by Paul Pearson -
Hi,

You can use ColumnTable() provided by the unionTables.pl macro (which is also automatically loaded by the unionTables.pl macro) to get a two column table in HTML mode that will revert to one column in TeX / PDF mode by stacking the left column on top of the right column. In the example below, I used a matching list, but multiple choice would have worked just as well.

You will need to be careful when defining the "hash table" of correct options listed.

A=>"A", B=>"B", C=>"C", D=>"D", E=>"E"

In particular, if you add one more choice to the problem, remember to add F=>"F" to the list above. Also, the quotes are necessary to ensure that things are interpreted as strings. I commented out the extra choices section below, but you can uncomment it.

Is this the kind of feature you wanted?

Best Regards,

Paul Pearson


###########################################
# Begin example


DOCUMENT();
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGcourse.pl",
"PGunion.pl",
);

##########################################
# Setup:

$ml = new_match_list();

$ml->qa(
"Spiderman", "\( 2 \) legs",
"Cow", "\( 4 \) legs",
"Box elder bug", "\( 6 \) legs",
"Spider","\( 8 \) legs",
);

$ml->rf_print_q(~~&pop_up_list_print_q); # use pop-up-lists
$ml -> ra_pop_up_list([ No_answer=>"?", A=>"A", B=>"B", C=>"C", D=>"D", E=>"E" ] );



$ml->choose(4);

#$ml->extra(
#"None of the above",
#"All of the above",
#);
#$ml->choose_extra(2);

$ml->makeLast("None of the above");

# End stuff to be edited
###########################################
# Main Text

TEXT(beginproblem());

BEGIN_TEXT
Match each living thing (real or fictitious) with its usual number of legs.
\{
ColumnTable(
$PAR.$ml->print_q.$PAR,
$ml->print_a,
indent => 0, separation => 30, valign => "TOP"
)
\}
END_TEXT

############################################
# Answers

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

ANS(str_cmp( $ml->ra_correct_ans ) );

ENDDOCUMENT();

In reply to Paul Pearson

Re: Multiple choice in tables and tables do not export well

by Hedley Pinsent -
Well thank you.

The TEXT($BEGIN_ONE_COLUMN);
and TEXT($END_ONE_COLUMN); has done the trick.

I will look at "Column Table()" a little later; it may offer some improvements.

I may use "one column" for all of the problems in the homework sets; very rarely are they printed and those that do may like the extra space to jot things down.

Students no longer like paper; they do them on their cell phones. Some will even do "theirs" in class while you are explaining another.

I will be surviving an era using "TEXT($BEGIN_ONE_COLUMN);".

Applets are presently being developed to convert what the user sees on the screen to presentable printed output. The world is in the process of looking after us.


The modified example is below [ note that the storyline comes from "Lind, Marchal, and Wathen" Statistical Techniques in Business and Economics]

## DESCRIPTION
## Statistics
## ENDDESCRIPTION

## KEYWORDS('Statistics','Distribution')
## Tagged by

## DBsubject('Statistics')
## DBchapter('Sampling Distributions and the Central Limit Theorem')
## DBsection('Sample Mean')
## Date('')
## Author('')
## Institution('CNA')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')


#
# First comes some stuff that appears at the beginning of every problem
#

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(
"PG.pl",
"MathObjects.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"PGasu.pl",
"PGstatisticsmacros.pl",
"PGnumericalmacros.pl",
);

TEXT($BEGIN_ONE_COLUMN,beginproblem()) ;

$alpha = list_random(0.01,0.05,0.10,0.20);
#upper tailed test
$zCritical = normal_distr(0.5 - $alpha);
$mean = random( 4, 10, 1);
$zTest = $zCritical;
while ( abs ($zTest - $zCritical) < 0.02){$zTest = random (0.5, 2.8, 0.1)};
$n = random (20,50,5);
#$sign = list_random(1,-1);
$sign = 1.0 ;
$sigma = list_random (0.3,0.4,0.5,0.6,0.7,0.8);

$xCritical = $mean + $sign * $zCritical * $sigma / sqrt $n;

#we round away from the critical values
####if($zTest * $sign > $zCritical * $sign){
####$xbar = int( 1.0 + 100 * ($mean + $sign * $zTest * $sigma ))/100;
####} else {
####$xbar = int( 100 * ($mean + $sign * $zTest * $sigma ))/100;}

$xbar = int( 100 * ($mean + $sign * $zTest * $sigma/sqrt $n ))/100;
#recalculating z
$zTest = ($xbar - $mean)/($sigma / sqrt $n);

$mcnull = new_multiple_choice();
$mcnull->qa(
"",
"\( \mu \)"
);
$mcnull->extra(
"\( \bar x \)",
"\( p \)","\( \bar p \)",
);

$mcnullEQ = new_multiple_choice();
$mcnullEQ->qa(
"", "\( \le \)"

);
$mcnullEQ->extra(
"\( \ge \)",
"\( \ne \)","\( \gt \)","\( \lt \)" ,"\( = \)"
);

$mcalt = new_multiple_choice();
$mcalt->qa(
"",
"\( \mu \)"
);
$mcalt->extra(
"\( \bar x \)",
"\( p \)","\( \bar p \)",
);


$mcaltEQ = new_multiple_choice();
$mcaltEQ->qa(""
,
"\( \gt \)"
);
$mcaltEQ->extra(
"\( \le \)",
"\( = \)","\( \lt \)", "\( \ne \)","\( \ge \)"
);


##SETTING UP THE TABLE

@r1 = ("\(H_0\)", $mcnull->print_a() ,$mcnullEQ->print_a(),NAMED_ANS_RULE("mu1",6));
@r2 = ("\(H_1\)",$mcalt->print_a(),$mcaltEQ->print_a(),NAMED_ANS_RULE("mu2",6) );

$mcTestStatistic = new_multiple_choice();
$mcTestStatistic->qa(
"The test statistic is",
"\( z \)"
);
$mcTestStatistic->extra(
"\( t \)",
"\( F \)","\( \chi^2 \)",
);

# Test Statistics choices

$mctestEQ = new_multiple_choice();
$mctestEQ->qa(
"",
"\( \gt \)"
);
$mctestEQ->extra("\( \lt or \gt \)". " -/+"
,
"\( \lt \)"
);


@r3 = ("We reject if: ", $mcTestStatistic->print_a() ,$mctestEQ->print_a(),NAMED_ANS_RULE("zCrit",6));


$mcAR = new_multiple_choice();




## this is a two-tailed test
$testStatistic = 0; # for now
if( abs($zTest) >abs ($zCritical) ){$mcAR->qa(
"We",
"reject"
);
$mcAR->extra(
"do not reject"
);}
else{$mcAR->qa(
"We",
"do not reject"
);
$mcAR->extra(
"reject"
);}

BEGIN_TEXT
The mean annual turnover rate of the 200-count bottle of Bayer Aspirin is $mean with a standard deviation of $sigma. (This indicates that the stock of Bayer Aspirin turns over on the pharmacy shelves an average of $mean times per year.) It is suspected that the mean turnover has changed and is more than $mean. $PAR

A random sample of $n of the 200-count Bayer Aspirin showed a mean of $xbar.
$PAR
Use the $alpha significance level to test the hypothesis that the turnover rate has increased.


$PAR





\{begintable(4)\}

\{row( @r1)\}
\{row( @r2)\}

\{endtable()\}


$PAR

$PAR
\(\alpha \) = \{NAMED_ANS_RULE("alpha",6)\} $PERCENT $BR


$BR

\{begintable(4)\}
\{row( @r3)\}
\{endtable()\}
$PAR
The value of the test statistic is \{NAMED_ANS_RULE("zTest",6)\} $PAR

\{$mcAR->print_q()\}
\{$mcAR->print_a()\}
$PAR
The p-value is \{NAMED_ANS_RULE("pValue",6)\} $PERCENT

END_TEXT

#CHECKING FIRST ROW H0
ANS( radio_cmp( $mcnull->correct_ans() ) );
ANS( radio_cmp( $mcnullEQ->correct_ans() ) );
NAMED_ANS(mu1=>num_cmp( $mean, mode=>"arith", reltol=>.01));

#CHECKING SECOND ROW H1
ANS( radio_cmp( $mcalt->correct_ans() ) );
ANS( radio_cmp( $mcaltEQ->correct_ans() ) );
NAMED_ANS(mu2=>num_cmp( $mean, mode=>"arith", reltol=>.01));

#checking alpha in percent
NAMED_ANS(alpha=>num_cmp( 100 * $alpha, mode=>"arith", reltol=>.01));

#CHECKING THIRD ROW
ANS( radio_cmp( $mcTestStatistic->correct_ans() ) );
ANS( radio_cmp( $mctestEQ->correct_ans() ) );
NAMED_ANS(zCrit=>num_cmp( $zCritical, mode=>"arith", reltol=>2));
#CHECKING FORTH ROW


NAMED_ANS(zTest=>num_cmp( $zTest, mode=>"arith", reltol=>2));

ANS( radio_cmp( $mcAR->correct_ans() ) );


$pValue = normal_prob (abs($zTest),infty);
#$Tol = normal_prob ($zTest - 0.02,$zTest);
$Tol = 0.001;
NAMED_ANS(pValue=>num_cmp( 100 * $pValue, mode=>"arith", tolerance=>0.5, tolType=>"absolute"));
TEXT($END_ONE_COLUMN);
ENDDOCUMENT(); # This should be the last executable line in the problem.