LaTeX::Table - Perl extension for the automatic generation of LaTeX tables.
This document describes LaTeX::Table version 0.0.1
use LaTeX::Table; my $data = [ [ 'Lisa', '0', '0' ], [ 'Marge', '0', '1' ], [ 'Homer', '2', '6' ], [], # horizontal line [ 'Wiggum', '0', '5' ], [ 'Otto', '1', '3' ], [ 'Barney', '8', '16' ], ]; my $header = [ [ 'Name', 'Beers:2|c|' ], [ '', 'before 4pm', 'after 4pm' ] ]; my $table = LaTeX::Table->new( { filename => 'counter.tex', caption => 'Number of beers before and after 4pm.', maincaption => 'Beer Counter', label => 'table_beercounter', theme => 'Houston', tablepos => 'htb', } ); # write LaTeX code in counter.tex $table->generate( $header, $data );
LaTeX::Table provides functionality for an intuitive and easy generation of LaTeX tables for reports or theses. It ships with some predefined good looking table styles. Supports multipage tables via the xtab package.
my $table = LaTeX::Table->new($arg_ref)
Constructs a LaTeX::Table object. The parameter is an hash reference with options (see below).
$table->generate($header, $data)
Generates the LaTeX table code. The two parameters are references to an array (the rows) of array references (the columns), once for the header and once for the data. An empty columns array produces an horizontal line (the '\hline' LaTeX command). The generated LaTeX table can be included in a LaTeX document with the \input command:
\input
% include counter.tex, generated by LaTeX::Table \input{counter}
$table->generate_string($header, $data)
Same as generate() but does not create a LaTeX file but returns the LaTex code as string.
my $latexcode = $table->generate_string($header, $data);
$table->get_available_themes()
Returns an hash reference to all available (predefined and customs) themes. See THEMES for details.
foreach my $theme ( keys %{ $table->get_available_themes } ) { ... }
Options can be defined in the constructor hash reference or with the setter set_<optionname>. Additionally, getters of the form get_<optionname> are created.
filename
The name of the LaTeX output file. Default is 'latextable.tex'.
label
The label of the table. Default is 'latextableperl'. In Latex, you can then create a reference to the table with \ref{label}.
type
Can be either 'std' for the standard LaTeX table or 'xtab' for a xtabular table for multipage tables. The later requires the xtab latex-package (\usepackage{xtab} in your LaTeX document). Default is 'std'.
caption
The caption of the table. Default is ''.
maincaption
If set, then this caption will be displayed in the Table Listing (\listoftables) and before the caption. Default unset.
theme
The name of the theme. Default is 'Dresden'.
tablepos
The position of the table, e.g. 'htb'. Default unset.
center
Defines whether the table is centered. Default 1 (centered).
size
Font size. Valid values are 'tiny', 'scriptsize', 'footnotesize', 'small', 'normal', 'large', 'Large', 'LARGE', 'huge', 'Huge' and 0. Default is 0 (does not define a font size).
tabledef
The table definition, e.g. '|l|r|c|r|'. If unset, LaTeX table tries to guess a good definition. Columns containing only numbers are right-justified, others left-justified. Default unset (guess good definition).
tabletailmsg
Message at the end of a multipage table. Default is 'Continued on next page'. 'xtab' only.
tabletail
Custom table tail. Default is multicolumn with the tabletailmsg (see above) right-justified. 'xtab' only.
xentrystretch
Option for xtab. Play with this option if the number of rows per page is not optimal. Requires a number as parameter. Default is 0 (does not use this option). 'xtab' only.
$table->set_xentrystretch(-0.1);
predef_themes
All predefined themes. Getter only.
custom_themes
All custom themes. Getter and setter only.
Multicolumns can be defined in LaTeX with \multicolumn{#cols}{definition}{text}. Because multicolumn are often needed and this is way too much code to type, a shortcut was implemented. Now, text:#colsdefinition is equivalent to original LaTeX code. For example, Beers:2|c| is equivalent to \multicolumn{2}{|c|}{Beers}. Note that |c| overrides the LINES settings in the theme (See Custom Themes).
The theme can be selected with $table->set_theme($themename). Currently, following predefined themes are available: Dresden, Miami, Houston. The script generate_examples.pl in the examples directory of this distributions generates some examples for all available themes.
Custom themes can be defined with an array reference containing all options (explained later):
my $themes = { 'Leipzig' => { 'HEADER_FONT_STYLE' => 'sc', 'HEADER_CENTERED' => 1, 'CAPTION_FONT_STYLE' => 'sc', 'VERTICAL_LINES' => [ 1, 2, 1 ], 'HORIZONTAL_LINES' => [ 1, 2, 0 ], }, }; $table->set_custom_themes($themes);
HEADER_FONT_STYLE, CAPTION_FONT_STYLE. Valid values are 'bf' (bold), it (italics), sc (caps) and tt (typewriter).
HEADER_FONT_STYLE
CAPTION_FONT_STYLE
VERTICAL_LINES, HORIZONTAL_LINES. A reference to an array with three integers, e.g. [ 1, 2, 0 ]. The first integer defines the number of outer lines. The second the number of lines after the header and after the first column. The third is the number of inner lines.
VERTICAL_LINES
HORIZONTAL_LINES
HEADER_CENTERED. Valid values are 0 (not centered) or 1 (centered).
HEADER_CENTERED
LaTeX::Table requires no configuration files or environment variables.
None reported.
No bugs have been reported.
Please report any bugs or feature requests to bug-latex-table@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-latex-table@rt.cpan.org
There are many limitations. This module does not want to provide thousands of useless options. However, if a particular - good looking - LaTeX table is not possible to generate with LaTeX::Table, it is considered as a bug. Please sent appropriate example LaTeX code to me. If you think your table theme looks better than the default ones, then please let me know your theme settings.
Markus Riester <mriester@gmx.de>
<mriester@gmx.de>
Copyright (c) 2006, Markus Riester <mriester@gmx.de>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
To install LaTeX::Table, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LaTeX::Table
CPAN shell
perl -MCPAN -e shell install LaTeX::Table
For more information on module installation, please visit the detailed CPAN module installation guide.