This is a perl script that converts a tab-delimited text file
to a colorful latex table. The colors are there for a good reason:
it makes the tables much more readable. If you don't like this,
you can always switch them off anyway.
The file generated can be include via an
\include
statement.
This is especially useful for publishing spreadsheets in a standard printable format on the web ( pdf ), and making them look nice. It also makes it easier for latex lovers to stick with latex as their complete publishing solution rather than resorting to inferior tools. It also has the advantage that it automates most of the formatting.
Here's some Sample output in PDF format.
unpack the archive
tar xvzf tablefilter.tgz
Then run the installer:
./install
This uses the longtable environment. The advantage of this is that if your table is too long to fit on one page, you won't run into trouble. It also uses the colortbl package to produce colored tables.
You will need to put the following in the preamble of
your latex file to use this:
\usepackage{colortbl}
\usepackage{longtable}
To use it, simply type :
tablefilter filename > output_file.tex
Where output_file.tex
is the name of the destination
file and filename
is the tab delimited text file.
The program will attempt to guess the number of columns in the table.
Alternatively, you can specify this on the command line if for some reason, you wish to have more columns than there are in your tab delimted text file.
tablefilter -c 4 filename > output_file.tex
Where you replace 4 with the number of columns you want.
You can use the -h
number to specify the row number
that precedes an \endhead
command. All rows up to and including
this one will be part of the table header. The first row is given the number 0
In other words, they will
appear at the top of each page on which the table appears. This has no effect
unless the table is more than one page long.
An example:
tablefilter -h 3 filename >output_file.tex
will put the first four rows of the table on the top of each page.
You may specify a table definition with the command ( for example )
tablefilter -d 'l |cc| r|r|r|r' -c 7 filename > output_file.tex
Note that you must specify the number of columns when using this option.
The package comes with several formats. The ``formats'' are nothing
more than a bunch of variable definitions used by the program. The format
files all have a .pl
extension, but you don't need to include the
extension when you invoke the tablefilter. As an example,
tablefilter -f d filename > output_file.tex
formats the table using the format file d.pl
( which is the default format ).
Formats included are:
d.pl | default format |
h0.pl | format with header row and no colors. |
h1.pl | Alternating gray rows and one header row. |
p.pl | Plain format. No colors. |
c.pl | Alternating colors in the columns. This only works for tables 16 columns wide, so you'll need to customise this file for different table sizes. |
The best way to understand how format files work is play around with
d.pl
and experiment. The format file d.pl
includes lots of comments and lots of different options.
The variables color[n]
represent
the colors that are repeated over. For example, the first
row will be color[0]
, the second row will be
the color color[1]
. If color[2]
does
not exist, all even numbered rows will be color[0]
For example, if you have this:
$color[0]="[gray]{0.9}"; $color[1]="[gray]{0.8}"; $color[2]="[gray]{0.7}";
Then row 3n
will be color [gray]{0.9}, row
(3n + 1 ) will be color [gray]{0.8} and row (3n + 2 ) will be
color [gray]{0.7}.
You can also define some rows that break the pattern. For example, If you have
$special_colors{0}="[rgb]{0.9,0.8,0.4}"; $special_colors{154}="[rgb]{1,0,0}"; $special_colors{157}="[gray]{0.6}";Then row 0 will be bright yellow row 154 wil be bright red, and row 157 will be gray 0.6 , overriding the other directives. Note that you don't need to define "special_color"s for rows 1-153 and 155-156. You only need to define it for the rows you want to color differently.
Header rows can also be defined in the format file. In other words, if you have a
multi page table and want rows 0-n ( remember, the rows are numbered from 0 )
appearing on each page,
modify the definition of $header_row
. If you don't
want any headers, you can disable it by setting
$header_row=-1
You can specify the shape of the table in the config file by setting the
variable $table_args
. The $table_args
variable
is placed in the table definition in this form:
\begin{longtable}{$table_args}
The longtable environment behaves the same way as the table environment, the main difference is that it can span several pages. You can also put color tags in this. Note that you need two backslashes if you want to specify latex commands eg like this:
$table_args="*{8} { >{\\columncolor[gray]{.8}}r >{\\columncolor[gray]{.9}}r }";
If you're not familiar with color tables, the above code makes a table with 16 right aligned colored columns. The *{n}{X} operator is an iterator that repeats the statement X n times over.
A simpler application of$table_args
involves just declaring the color of
the first column. For example,
$table_args=" >{\\columncolor[gray]{.8}} r rrr|r|";
specifies a table with five right aligned columns, the where first one is gray, and the last one has a border.