2017 Problem Authoring Workshop

Variable-length Tables?

Re: Variable-length Tables?

by Davide Cervone -
Number of replies: 0
Here is an example that creates a table with rows for each x between two randomly selected values. Perhaps that will be sufficient for you to modify it for your needs:

$x1 = random(-5,5,1);
$x2 = random($x1+1,$x1+5,1);

$f = Formula("x/2+1");

#  The first row of the table is headers for the columns
#    (formatted using LaTeX)
@xy = ([['\(x\)', header=>'CH'], ['\(y\)', header=>'CH']]);

#  Add the rows to the table.  The values are put between
#     \(  and \) so they will be formatted as mathematics
for $x ($x1..$x2) {
  push(@xy, ['\('.$x.'\)', '\('.$f->eval(x => $x).'\)']);

#  Create the table using DataTable().  The three stars are
#     so that the LaTeX will be formatted after being inserted.
    [@ DataTable( [ @xy ], align => "|c|c|", midrules=>1) @]***
Hope that gets you where you need to go.