File: longtable.py

package info (click to toggle)
python-pylatex 1.4.2%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: python: 3,810; sh: 209; makefile: 169; xml: 12
file content (42 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
"""
This example shows the functionality of the longtable element.

It creates a sample multi-page spanning table

..  :copyright: (c) 2017 by Jarrah Gosbell
    :license: MIT, see License for more details.
"""

# begin-doc-include
from pylatex import Document, LongTable, MultiColumn


def genenerate_longtabu():
    geometry_options = {"margin": "2.54cm", "includeheadfoot": True}
    doc = Document(page_numbers=True, geometry_options=geometry_options)

    # Generate data table
    with doc.create(LongTable("l l l")) as data_table:
        data_table.add_hline()
        data_table.add_row(["header 1", "header 2", "header 3"])
        data_table.add_hline()
        data_table.end_table_header()
        data_table.add_hline()
        data_table.add_row((MultiColumn(3, align="r", data="Continued on Next Page"),))
        data_table.add_hline()
        data_table.end_table_footer()
        data_table.add_hline()
        data_table.add_row(
            (MultiColumn(3, align="r", data="Not Continued on Next Page"),)
        )
        data_table.add_hline()
        data_table.end_table_last_footer()
        row = ["Content1", "9", "Longer String"]
        for i in range(150):
            data_table.add_row(row)

    doc.generate_pdf("longtable", clean_tex=False)


genenerate_longtabu()