Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JAEarly committed Nov 10, 2023
2 parents 586cc26 + 7b39232 commit 8c67c03
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ A working example is also given in this [Colab Notebook](https://colab.research.

## Release History

* 1.0.1
* Fixed bug with multicolumn headers missing horizontal and vertical lines. Thanks to [electricbrass](https://github.com/electricbrass).
* 1.0.0
* Added the ability to a list of rows rather than a Texttable object (Texttable is still a requirement).
Inspired by [latextable-lite](https://github.com/huisyy/latextable-lite) from [Huisyy](https://github.com/huisyy).
Expand Down
18 changes: 18 additions & 0 deletions examples/basic_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def run():
example_10()
example_11()
example_12()
example_13()


def example_1():
Expand Down Expand Up @@ -198,5 +199,22 @@ def example_12():
print(latextable.draw_latex(rows, use_booktabs=True, alias=alias))


def example_13():
# Example 13 - Multicolumn header with vertical and horizontal lines
rows = [["R", "A", "B", "C", "D"],
["1", "a1", "b1", "c1", "d1"],
["2", "a2", "b2", "c2", "d2"],
["3", "a3", "b3", "c3", "d3"]]
multicolumn_header = [("", 1), ("AB", 2), ("CD", 2)]

table_13 = Texttable()
table_13.add_rows(rows)
print('\n-- Example 13: Multicolumn header with vertical and horizontal lines --')
print('Texttable Output:')
print(table_13.draw())
print('Latextable Output:')
print(latextable.draw_latex(table_13, multicolumn_header=multicolumn_header))


if __name__ == "__main__":
run()
3 changes: 2 additions & 1 deletion latextable.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ def _draw_latex_header(table, drop_columns, use_booktabs, multicolumn_header):

# Multicolumn header
if multicolumn_header is not None:
multicolumn_header_str = ["\\multicolumn{{{:d}}}{{c}}{{{:s}}}".format(c, name) for name, c in multicolumn_header]
multicolumn_header_str = [f"\\multicolumn{{{count}}}{'{|c|}' if idx == 0 else '{c|}'}{{{name}}}" for idx, (name, count) in enumerate(multicolumn_header)]
out += _indent_text(" & ".join(multicolumn_header_str) + " \\\\\n", 3)
out += _indent_text("\\{}\n".format(rule), 3)

# Normal header
out += _indent_text(" & ".join(header) + " \\\\\n", 3)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "latextable"
version = "1.0.0"
version = "1.0.1"
authors = [{name = "Joseph Early", email = "[email protected]"}]
license = {text = "MIT"}
description = "An extension to the texttable library that exports tables directly to Latex."
Expand Down

0 comments on commit 8c67c03

Please sign in to comment.