version 1.1, 2010/08/18 12:04:31
|
version 1.4, 2011/04/13 10:44:26
|
Line 140 array element is a table row. However:
|
Line 140 array element is a table row. However:
|
These are treated as LaTeX/TeX commands and, when the table is generated, |
These are treated as LaTeX/TeX commands and, when the table is generated, |
passed without interpretation. |
passed without interpretation. |
|
|
=item Empty cells |
=item Lines with one cell that is empty. |
|
|
These produce a horizontal rule that spans the width of the table. |
These produce a horizontal rule that spans the width of the table. |
|
|
=back |
=back |
|
|
|
Calling this multiple times will continue to append cell data. |
|
|
=head3 Example |
=head3 Example |
|
|
$table->set_data([ ['Gnu', '92.52'], [], ['Emu', '33.33'] ]); |
$table->set_data([ ['Gnu', '92.52'], [], ['Emu', '33.33'] ]); |
Line 157 Produces
|
Line 159 Produces
|
| Emu | 33.33 | |
| Emu | 33.33 | |
+--------------+--------------+ |
+--------------+--------------+ |
|
|
|
|
=cut |
=cut |
|
|
sub set_data { |
sub set_data { |
my ($self, $data) = @_; |
my ($self, $data) = @_; |
$self->{'data'} = $data; |
my $current_data = $self->{'data'}; |
|
push (@$current_data, @$data); |
|
$self->{'data'} = $current_data; |
|
|
|
|
} |
} |
|
|
Line 222 sub generate_string {
|
Line 228 sub generate_string {
|
sub table_header() |
sub table_header() |
{ |
{ |
my ($self) = @_; |
my ($self) = @_; |
my $result = 'begin{tabular}['; |
my $result = '\begin{tabular}{'; |
my $coldef = $self->{'coldef'}; |
my $coldef = $self->{'coldef'}; |
|
|
if ($coldef eq '') { |
if ($coldef eq '') { |
Line 252 sub table_header()
|
Line 258 sub table_header()
|
# |
# |
sub table_body() |
sub table_body() |
{ |
{ |
return ''; |
my ($self) = @_; |
|
my $result = ''; |
|
foreach my $row (@{$self->{'data'}}) { |
|
# |
|
# If a row has only a single cell we need to deal with the two special cases |
|
# Pass LaTeX uninterpreted or \hline. |
|
# |
|
if ((scalar @{$row}) == 1) { |
|
my $cell = $row->[0]; |
|
if ($cell eq '') { |
|
$result .= '\hline' . "\n"; |
|
} elsif (substr($cell, 0, 1) eq "\\") { |
|
$result .= $cell . "\n"; |
|
} else { |
|
# could just be a table with one col... |
|
|
|
$result .= $cell . ' \\\\ ' ."\n"; |
|
} |
|
} else { |
|
my $line = ''; |
|
foreach my $cell (@{$row}) { |
|
$line .= $cell . ' & '; |
|
} |
|
# Replace the last ' & ' with \\ and a line terminator.. |
|
# and append the line to the result. |
|
|
|
$line =~ s/ & $/ \\\\\n/; |
|
$result .= $line; |
|
} |
|
} |
|
return $result; |
} |
} |
|
|
# |
# |