Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Nicely wrap long text in tables, due to tabulary.
Closes #41
  • Loading branch information
jest committed Dec 28, 2010
1 parent c696fe7 commit 7be2120
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/Perl6BookLatex.pm
Expand Up @@ -174,5 +174,42 @@ sub encode_text {
return $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;
3 changes: 3 additions & 0 deletions lib/book.sty
Expand Up @@ -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}

Expand Down

0 comments on commit 7be2120

Please sign in to comment.