Permalink
Browse files

Nicely wrap long text in tables, due to tabulary.

Closes #41
  • Loading branch information...
1 parent c696fe7 commit 7be21205abff00338773cd70c6c77d240a894057 @jest jest committed Dec 28, 2010
Showing with 40 additions and 0 deletions.
  1. +37 −0 lib/Perl6BookLatex.pm
  2. +3 −0 lib/book.sty
View
@@ -175,4 +175,41 @@ sub encode_text {
}
# --------------------------------------------------------------------
+# This one is copied from Pod::PseudoPod::LaTeX, at least till some
+# more customization of environments will be possible there. When it
+# happens, just remove the following sub and setup P::PP::LaTeX ot use
+# `tabulary' package with `L' column format specifiers.
+sub end_table
+{
+ my $self = shift;
+
+ # Format the table body
+ my $column_count = @{ $self->{table_rows}[0] };
+ my $format_spec = '|' . ( 'L|' x $column_count );
+
+ # first row is gray
+ $self->{scratch} .= "\\begin{tabulary}{\\columnwidth}{$format_spec}\n"
+ . "\\hline\n"
+ . "\\rowcolor[gray]{.9}\n";
+
+ # Format each row
+ my $row;
+ for $row ( @{ $self->{table_rows} } )
+ {
+ $self->{scratch} .= join( ' & ', @$row )
+ . "\\\\ \\hline\n";
+ }
+
+ # Close the table
+ $self->{scratch} .= "\\end{tabulary}\n"
+ . "\\end{center}\n"
+ . "\\end{table}\n";
+
+ $self->{flags}{in_table}--;
+ delete $self->{table_rows};
+
+ $self->emit();
+}
+
+# --------------------------------------------------------------------
1;
View
@@ -55,6 +55,9 @@ paperwidth=[% paper_width %],paperheight=[% paper_height %]
% Supplies 'tabular' environment and \rowcolor.
\usepackage{colortbl}
+% Used as a default tables env., nicely wrapping longer texts in cells
+\usepackage{tabulary}
+
% Optimize for this language.
\usepackage[english]{babel}

0 comments on commit 7be2120

Please sign in to comment.