Skip to content

Commit

Permalink
Table: Add width argument to override calculated width
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Aug 17, 2016
1 parent 82074d9 commit dbe8563
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Added
the Euro (€) Symbol can be used in the source.
- `.Quantity` got a new ``options`` keyword argument and learned to handle
uncertain quantities.
- `.Tabular` can now have a width specified to override the calculated width
based on the ``table_spec`` argument.

Fixed
~~~~~
Expand Down
13 changes: 11 additions & 2 deletions pylatex/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,30 @@ class Tabular(Environment):
'pos': 'options',
}

def __init__(self, table_spec, data=None, pos=None, **kwargs):
def __init__(self, table_spec, data=None, pos=None, *, width=None,
**kwargs):
"""
Args
----
table_spec: str
A string that represents how many columns a table should have and
if it should contain vertical lines and where.
pos: list
width: int
The amount of columns that the table has. If this is `None` it is
calculated based on the ``table_spec``, but this is only works for
simple specs. In cases where this calculation is wrong override the
width using this argument.
References
----------
* https://en.wikibooks.org/wiki/LaTeX/Tables#The_tabular_environment
"""

self.width = _get_table_width(table_spec)
if width is None:
self.width = _get_table_width(table_spec)
else:
self.width = width

super().__init__(data=data, options=pos,
arguments=table_spec, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_math():

def test_table():
# Tabular
t = Tabular(table_spec='|c|c|', data=None, pos=None)
t = Tabular(table_spec='|c|c|', data=None, pos=None, width=2)

t.add_hline(start=None, end=None)

Expand Down

0 comments on commit dbe8563

Please sign in to comment.