Skip to content

Commit

Permalink
Improve table layouting: increase vertical padding of table cells.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Jun 11, 2014
1 parent 03ab8af commit 0279a55
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/HISTORY.txt
Expand Up @@ -4,7 +4,9 @@ Changelog
1.3.2 (unreleased)
------------------

- Nothing changed yet.
- Improve table layouting.
Increase vertical padding of table cells.
[jone]


1.3.1 (2014-06-02)
Expand Down
3 changes: 2 additions & 1 deletion ftw/pdfgenerator/html2latex/subconverters/table.py
Expand Up @@ -149,7 +149,8 @@ def render(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-%i\tabcolsep}' % (
2 * len(self.columns))]
2 * len(self.columns)),
r'\renewcommand{\arraystretch}{1.4}']

caption_command, insert_caption_at_top = self.render_caption()
if caption_command and insert_caption_at_top:
Expand Down
43 changes: 43 additions & 0 deletions ftw/pdfgenerator/tests/test_html2latex_table_converter.py
Expand Up @@ -58,6 +58,7 @@ def test_table_converted(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{\textbf{My Head}} \\',
r'\multicolumn{1}{l}{My Body} \\',
Expand Down Expand Up @@ -91,6 +92,7 @@ def test_headings(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{ll}',
r'\multicolumn{1}{l}{\textbf{headA}} & ' + \
r'\multicolumn{1}{l}{\textbf{headB}} \\',
Expand Down Expand Up @@ -123,6 +125,7 @@ def test_colgroup_with_width(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.3\tablewidth}p{0.7\tablewidth}}',

r'\multicolumn{1}{p{0.3\tablewidth}}{test1} & '
Expand Down Expand Up @@ -155,6 +158,7 @@ def test_colgroup_with_invalid_width(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.3\tablewidth}r}',

r'\multicolumn{1}{p{0.3\tablewidth}}{test1} & '
Expand Down Expand Up @@ -190,6 +194,7 @@ def test_col_and_cell_have_widths(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.3\tablewidth}p{0.7\tablewidth}}',

r'\multicolumn{1}{p{0.3\tablewidth}}{'
Expand Down Expand Up @@ -225,6 +230,7 @@ def test_style_widths(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.3\tablewidth}p{0.7\tablewidth}}',

r'\multicolumn{1}{p{0.3\tablewidth}}{'
Expand Down Expand Up @@ -260,6 +266,7 @@ def test_style_widths_in_px(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{30.0em}p{70.0em}}',

r'\multicolumn{1}{p{30.0em}}{'
Expand Down Expand Up @@ -289,6 +296,7 @@ def test_caption_is_used(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',

r'\begin{center}',
r'\addtocounter{table}{1}',
Expand Down Expand Up @@ -323,6 +331,7 @@ def test_caption_not_listed(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',

r'\begin{center}',
r'NotIndexedCaption',
Expand Down Expand Up @@ -351,6 +360,7 @@ def test_caption_at_bottom(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',

r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{foo} \\',
Expand Down Expand Up @@ -386,6 +396,7 @@ def test_summary_as_caption(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',

r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{foo} \\',
Expand Down Expand Up @@ -417,6 +428,7 @@ def test_summary_as_not_listed_caption(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',

r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{foo} \\',
Expand All @@ -442,13 +454,15 @@ def test_multiple_tables(self):
r'\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{test1} \\',
r'\end{tabular}',
r'\makeatletter\@ifundefined{tablewidth}{\newlength' + \
r'\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{test2} \\',
r'\end{tabular}',
Expand All @@ -465,6 +479,7 @@ def test_convert_cell_html(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{\textbf{Hello} \textit{World}} \\',
r'\end{tabular}',
Expand All @@ -485,6 +500,7 @@ def test_convert_other_html(self):
r' \makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{test} \\',
r'\end{tabular}',
Expand All @@ -506,6 +522,7 @@ def test_htmlentities(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{2>1} \\',
'\\multicolumn{1}{l}{X\xc3\xa4Y} \\\\',
Expand Down Expand Up @@ -540,6 +557,7 @@ def test_colspan(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-6\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.33\tablewidth}p{0.33\tablewidth}'
r'p{0.34\tablewidth}}',

Expand Down Expand Up @@ -579,6 +597,7 @@ def test_rowspan(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multirow{2}{0.5\tablewidth}{one} & \multicolumn{1}'
Expand Down Expand Up @@ -622,6 +641,7 @@ def test_complex_rowspan_colspan(self):
r'\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-10\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.25\tablewidth}p{0.25\tablewidth}' + \
r'p{0.25\tablewidth}p{0.25\tablewidth}l}',

Expand Down Expand Up @@ -679,6 +699,7 @@ def test_rowspan_error_in_last_column(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',
r'\multicolumn{1}{p{0.5\tablewidth}}{A} &' + \
r' \multirow{2}{0.5\tablewidth}{2xB} \\',
Expand Down Expand Up @@ -714,6 +735,7 @@ def test_gridborder(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{|p{0.3\tablewidth}|p{0.7\tablewidth}|}',
r'\hline',

Expand Down Expand Up @@ -750,6 +772,7 @@ def test_newlines(self):
r'\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -781,6 +804,7 @@ def test_tabular_environment_depends_on_table_size(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -809,6 +833,7 @@ def test_longtable_environment_depends_on_table_size(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{longtable}{l}',
(40 * '\\multicolumn{1}{l}{foo} \\\\\n').strip(),
r'\end{longtable}',
Expand All @@ -833,6 +858,7 @@ def test_longtable_environment_enforcable_by_cssclass(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{longtable}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand All @@ -859,6 +885,7 @@ def test_tabular_environment_enforcable_by_cssclass(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
(20 * '\\multicolumn{1}{l}{foo} \\\\\n').strip(),
r'\end{tabular}',
Expand Down Expand Up @@ -934,6 +961,7 @@ def test_simple_grid_css_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{|l|l|}',
r'\hline',

Expand Down Expand Up @@ -985,6 +1013,7 @@ def test_complex_grid_css_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-6\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{|p{0.5\tablewidth}|p{0.25\tablewidth}|' + \
r'p{0.25\tablewidth}|}',
r'\hline',
Expand Down Expand Up @@ -1038,6 +1067,7 @@ def test_border_rowspan_collapse(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-8\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.25\tablewidth}p{0.25\tablewidth}' + \
r'p{0.25\tablewidth}p{0.25\tablewidth}}',

Expand Down Expand Up @@ -1087,6 +1117,7 @@ def test_listing_css_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-6\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.25\tablewidth}' + \
r'p{0.25\tablewidth}}',
r'\hline',
Expand Down Expand Up @@ -1141,6 +1172,7 @@ def test_vertical_css_class_makes_first_column_bold(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-6\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.25\tablewidth}' + \
r'p{0.25\tablewidth}}',

Expand Down Expand Up @@ -1180,6 +1212,7 @@ def test_colspan_without_width(self):
r'\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{ll}',

r'\multicolumn{1}{l}{foo} & ' + \
Expand Down Expand Up @@ -1214,6 +1247,7 @@ def test_border_classes(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-6\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{lll}',

r'\cline{2-2}',
Expand Down Expand Up @@ -1259,6 +1293,7 @@ def test_alignment_classes(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{l}',
r'\multicolumn{1}{l}{left} \\',
r'\multicolumn{1}{c}{center} \\',
Expand All @@ -1269,6 +1304,7 @@ def test_alignment_classes(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-2\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{1.0\tablewidth}}',
r'\multicolumn{1}{p{1.0\tablewidth}}{\raggedright left} \\',
r'\multicolumn{1}{p{1.0\tablewidth}}{' + \
Expand All @@ -1294,6 +1330,7 @@ def test_indent2_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -1321,6 +1358,7 @@ def test_indent10_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -1348,6 +1386,7 @@ def test_bold_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -1375,6 +1414,7 @@ def test_grey_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -1403,6 +1443,7 @@ def test_footnotesize_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -1430,6 +1471,7 @@ def test_scriptsize_class(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down Expand Up @@ -1458,6 +1500,7 @@ def test_ragged_and_style_order(self):
r'\makeatletter\@ifundefined{tablewidth}{\newlength\tablewidth}\makeatother',
r'\setlength\tablewidth\linewidth',
r'\addtolength\tablewidth{-4\tabcolsep}',
r'\renewcommand{\arraystretch}{1.4}',
r'\begin{tabular}{p{0.5\tablewidth}p{0.5\tablewidth}}',

r'\multicolumn{1}{p{0.5\tablewidth}}{' + \
Expand Down

0 comments on commit 0279a55

Please sign in to comment.