Skip to content

Commit

Permalink
Add new tabletypes: tabu, longtable and longtabu.
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Mar 18, 2014
1 parent 22cf991 commit f03ac78
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions pylatex/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ class Table(BaseLaTeXContainer):

"""A class that represents a table."""

def __init__(self, table_spec, data=None, pos=None):
def __init__(self, table_spec, data=None, pos=None, packages=None):
self.table_type = 'tabular'
self.table_spec = table_spec
self.pos = pos

self.width = get_table_width(table_spec)

super().__init__(data)
super().__init__(data=data, packages=packages)

def add_hline(self, start=None, end=None):
"""Add a horizontal line to the table"""
Expand Down Expand Up @@ -87,7 +88,7 @@ def add_multirow(self, size, align, content, hlines=True, cells=None,

def dumps(self):
"""Represents the document as a string in LaTeX syntax."""
string = r'\begin{tabular}'
string = r'\begin{' + self.table_type + '}'

if self.pos is not None:
string += '[' + self.pos + ']'
Expand All @@ -96,7 +97,35 @@ def dumps(self):

string += dumps_list(self)

string += r'\end{tabular}'
string += r'\end{' + self.table_type + '}'

super().dumps()
return string


class Tabu(Table):

"""A class that represents a tabu (more flexible table)"""

def __init__(self, *args, **kwargs):
super().__init__(*args, packages=[Package('tabu')], **kwargs)
self.table_type = 'tabu'


class LongTable(Table):

"""A class that represents a longtable (multipage table)"""

def __init__(self, *args, **kwargs):
super().__init__(*args, packages=[Package('longtable')], **kwargs)
self.table_type = 'longtable'


class LongTabu(Table):

"""A class that represents a longtabu (more flexible multipage table)"""

def __init__(self, *args, **kwargs):
packages = [Package('tabu'), Package('longtable')]
super().__init__(*args, packages=packages, **kwargs)
self.table_type = 'longtabu'

0 comments on commit f03ac78

Please sign in to comment.