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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#!/usr/bin/python
"""
This example shows the functionality of the Tabu and LongTabu element.
.. :copyright: (c) 2016 by Vladimir Gorovikov and Scott Wallace
:license: MIT, see License for more details.
"""
# begin-doc-include
from random import randint
from pylatex import Center, Document, LongTabu, Tabu
from pylatex.utils import bold
def genenerate_tabus():
geometry_options = {
"landscape": True,
"margin": "1.5in",
"headheight": "20pt",
"headsep": "10pt",
"includeheadfoot": True,
}
doc = Document(page_numbers=True, geometry_options=geometry_options)
# Generate data table with 'tight' columns
fmt = "X[r] X[r] X[r] X[r] X[r] X[r]"
with doc.create(LongTabu(fmt, spread="0pt")) as data_table:
header_row1 = ["Prov", "Num", "CurBal", "IntPay", "Total", "IntR"]
data_table.add_row(header_row1, mapper=[bold])
data_table.add_hline()
data_table.add_empty_row()
data_table.end_table_header()
data_table.add_row(["Prov", "Num", "CurBal", "IntPay", "Total", "IntR"])
row = ["PA", "9", "$100", "%10", "$1000", "Test"]
for i in range(40):
data_table.add_row(row)
with doc.create(Center()) as centered:
with centered.create(Tabu("X[r] X[r]", spread="1in")) as data_table:
header_row1 = ["X", "Y"]
data_table.add_row(header_row1, mapper=[bold])
data_table.add_hline()
row = [randint(0, 1000), randint(0, 1000)]
for i in range(4):
data_table.add_row(row)
with doc.create(Center()) as centered:
with centered.create(Tabu("X[r] X[r]", to="4in")) as data_table:
header_row1 = ["X", "Y"]
data_table.add_row(header_row1, mapper=[bold])
data_table.add_hline()
row = [randint(0, 1000), randint(0, 1000)]
for i in range(4):
data_table.add_row(row)
doc.generate_pdf("tabus", clean_tex=False)
genenerate_tabus()
|