Skip to content

Added row height modifier to both normal and empty rows. Added colour… #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions pylatex/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,36 @@ def add_hline(self, start=None, end=None, *, color=None,
self.append(Command(cline,
dumps_list([start, NoEscape('-'), end])))

def add_empty_row(self):
"""Add an empty row to the table."""
# To prevent repeating code, is there some way that we can just
# have calls to this method in turn call add_row but the cells
# are all just empty?
def add_empty_row(self, color=None, height_modifier=None):
"""Add an empty row to the table.

self.append(NoEscape((self.width - 1) * '&' + r'\\'))
Args
----
color: str
The name of the color used to highlight the row
height_modifier: str
The height modifier appended to the end of a table row.
Example: `Some&Cells&Here\\\\[-0.5em]`
"""

if color:
if not self.color:
self.packages.append(Package("xcolor", options='table'))
self.color = True
color_command = Command(command="rowcolor", arguments=color)
self.append(color_command)

def add_row(self, *cells, color=None, escape=None, mapper=None,
strict=True):
to_append = NoEscape((self.width - 1) * '&' + r'\\')
if height_modifier:
to_append += NoEscape('[{}]'.format(height_modifier))

self.append(to_append)

def add_row(self, *cells, color=None, escape=None, height_modifier=None,
mapper=None, strict=True):
"""Add a row of cells to the table.

Args
Expand All @@ -216,14 +239,17 @@ def add_row(self, *cells, color=None, escape=None, mapper=None,
contents.
color: str
The name of the color used to highlight the row
height_modifier: str
The height modifier appended to the end of a table row.
Example: `Some&Cells&Here\\\\[-0.5em]`
mapper: callable or `list`
A function or a list of functions that should be called on all
entries of the list after converting them to a string,
for instance bold
strict: bool
Check for correct count of cells in row or not.
"""

if len(cells) == 1 and _is_iterable(cells):
cells = cells[0]

Expand Down Expand Up @@ -257,9 +283,12 @@ def add_row(self, *cells, color=None, escape=None, mapper=None,
color_command = Command(command="rowcolor", arguments=color)
self.append(color_command)

self.append(dumps_list(cells, escape=escape, token='&',
mapper=mapper) + NoEscape(r'\\'))
to_append = dumps_list(cells, escape=escape, token='&',
mapper=mapper) + NoEscape(r'\\')
if height_modifier:
to_append += NoEscape('[{}]'.format(height_modifier))

self.append(to_append)

class Tabularx(Tabular):
"""A class that represents a tabularx environment."""
Expand Down