Name | etabs JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | Python library for rendering latex tables in an easy way |
upload_time | 2024-10-21 09:54:55 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | MIT License Copyright (c) 2022 yupidevs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
latex
table
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# etabs
Python library for building and rendering latex tables in an easy way.
## Instalation
```bash
pip install etabs
```
## Simple example
Code:
```python
from etabs import RuleType, TexTable
# Example values
values = [
[60, 20, 20],
[50, 40, 10],
[30, 10, 60],
[5, 90, 5],
]
row_labels = ["A", "B", "C", "D"]
col_labels = ["C1", "C2", "C3"]
# TexTabel is the main structure for creating tables
table = TexTable(centered=True, caption="Example table")
# Add rows
table.add_row(None, *col_labels) # First value empty, rest are column labels
for label, row in zip(row_labels, values):
table.add_row(label, *row)
# You can optionally add rules at specific rows
table.add_rule(0, RuleType.TOP)
table.add_rule(1) # By default, the rule is a midrule
# If no row is specified, it will be added at the end
table.add_rule(rule_type=RuleType.BOTTOM)
# Finally to get the latex code use the render method
print(table.render())
```
Output:
```latex
\begin{figure}[h!]
\centering
\caption{Example table}
\vspace{0.5em}
\begin{tabular}{cccc}
\toprule
& C1 & C2 & C3 \\
\midrule
A & 60 & 20 & 20 \\
B & 50 & 40 & 10 \\
C & 30 & 10 & 60 \\
D & 5 & 90 & 5 \\
\bottomrule
\end{tabular}
\end{figure}
```
Result:
<p align="center"><img src="./.images/simple.jpg" alt="simple" width=300></p>
## A little more styled example
```python
from etabs import RuleType, TexTable
# Example values
values = [
[60, 20, 20],
[50, 40, 10],
[30, 10, 60],
[5, 90, 5],
]
col_labels = ["C1", "C2", "C3"]
table = TexTable(centered=True, caption="Example table")
# Add values
table.add_row(*col_labels, start=2) # Colum 0 and 1 are empty
for row in values:
# Preprocess each value to show as percentage
table.add_row(*row, prep=lambda x: f"{x} \\%", start=2)
# Add a vertical separator before column 2
table.seps[2] = "|"
# Assign values directly
table[1, 1] = table[3, 1] = "A1"
table[2, 1] = table[4, 1] = "B2"
# Merge cells using slices
table[0, 0:2] = "Types"
table[1:3, 0] = "Typa A"
table[3:, 0] = "Typa B"
# Add some style using slices too
table[0, :].set_bold(True)
table[:, 0:2].set_bold(True)
table[1:, 0:2].set_italic(True)
# Add rules
table.add_rule(0, RuleType.TOP)
table.add_rule(1)
table.add_rule(rule_type=RuleType.BOTTOM)
print(table.render())
```
Output:
```latex
\begin{figure}[h!]
\centering
\caption{Example table}
\vspace{0.5em}
\begin{tabular}{cc|ccc}
\toprule
\multicolumn{2}{c|}{\textbf{Types}} & \textbf{C1} & \textbf{C2} & \textbf{C3} \\
\midrule
\multirow{2}{*}{\textit{\textbf{Typa A}}} & \textit{\textbf{A1}} & 60 \% & 20 \% & 20 \% \\
& \textit{\textbf{B2}} & 50 \% & 40 \% & 10 \% \\
\multirow{2}{*}{\textit{\textbf{Typa B}}} & \textit{\textbf{A1}} & 30 \% & 10 \% & 60 \% \\
& \textit{\textbf{B2}} & 5 \% & 90 \% & 5 \% \\
\bottomrule
\end{tabular}
\end{figure}
```
Result:
<p align="center"><img src="./.images/complex.jpg" alt="simple" width=480></p>
## Latex packages
According the commands you use, some packages may need to be added to the
document for the correct rendering of the table.
To see the dependencies for a given table you can use de `render_deps` method:
```python
# following the example from the last section
print(table.render_deps())
```
Output:
```
\usepackage{multirow}
\usepackage{booktabs}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "etabs",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "latex, table",
"author": null,
"author_email": "Jorge Morgado Vega <jorge.morgadov@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/05/57/6d98f167d5cbe7f129047411a630f798998d01ea90624c3c31c4d898d9d0/etabs-0.2.0.tar.gz",
"platform": null,
"description": "# etabs\n\nPython library for building and rendering latex tables in an easy way.\n\n## Instalation\n\n```bash\npip install etabs\n```\n\n## Simple example\n\nCode:\n```python\nfrom etabs import RuleType, TexTable\n\n# Example values\nvalues = [\n [60, 20, 20],\n [50, 40, 10],\n [30, 10, 60],\n [5, 90, 5],\n]\n\nrow_labels = [\"A\", \"B\", \"C\", \"D\"]\ncol_labels = [\"C1\", \"C2\", \"C3\"]\n\n# TexTabel is the main structure for creating tables\ntable = TexTable(centered=True, caption=\"Example table\")\n\n# Add rows\ntable.add_row(None, *col_labels) # First value empty, rest are column labels\nfor label, row in zip(row_labels, values):\n table.add_row(label, *row)\n\n# You can optionally add rules at specific rows\ntable.add_rule(0, RuleType.TOP)\ntable.add_rule(1) # By default, the rule is a midrule\n\n# If no row is specified, it will be added at the end\ntable.add_rule(rule_type=RuleType.BOTTOM)\n\n# Finally to get the latex code use the render method\nprint(table.render())\n```\n\nOutput:\n```latex\n\\begin{figure}[h!]\n \\centering\n \\caption{Example table}\n \\vspace{0.5em}\n \\begin{tabular}{cccc}\n \\toprule\n & C1 & C2 & C3 \\\\\n \\midrule\n A & 60 & 20 & 20 \\\\\n B & 50 & 40 & 10 \\\\\n C & 30 & 10 & 60 \\\\\n D & 5 & 90 & 5 \\\\\n \\bottomrule\n \\end{tabular}\n\\end{figure}\n```\n\nResult:\n\n<p align=\"center\"><img src=\"./.images/simple.jpg\" alt=\"simple\" width=300></p>\n\n## A little more styled example\n\n```python\nfrom etabs import RuleType, TexTable\n\n# Example values\nvalues = [\n [60, 20, 20],\n [50, 40, 10],\n [30, 10, 60],\n [5, 90, 5],\n]\n\ncol_labels = [\"C1\", \"C2\", \"C3\"]\n\ntable = TexTable(centered=True, caption=\"Example table\")\n\n# Add values\ntable.add_row(*col_labels, start=2) # Colum 0 and 1 are empty\nfor row in values:\n # Preprocess each value to show as percentage\n table.add_row(*row, prep=lambda x: f\"{x} \\\\%\", start=2)\n\n# Add a vertical separator before column 2\ntable.seps[2] = \"|\"\n\n# Assign values directly\ntable[1, 1] = table[3, 1] = \"A1\"\ntable[2, 1] = table[4, 1] = \"B2\"\n\n# Merge cells using slices\ntable[0, 0:2] = \"Types\"\ntable[1:3, 0] = \"Typa A\"\ntable[3:, 0] = \"Typa B\"\n\n# Add some style using slices too\ntable[0, :].set_bold(True)\ntable[:, 0:2].set_bold(True)\ntable[1:, 0:2].set_italic(True)\n\n# Add rules\ntable.add_rule(0, RuleType.TOP)\ntable.add_rule(1)\ntable.add_rule(rule_type=RuleType.BOTTOM)\n\nprint(table.render())\n```\n\nOutput:\n```latex\n\\begin{figure}[h!]\n \\centering\n \\caption{Example table}\n \\vspace{0.5em}\n \\begin{tabular}{cc|ccc}\n \\toprule\n \\multicolumn{2}{c|}{\\textbf{Types}} & \\textbf{C1} & \\textbf{C2} & \\textbf{C3} \\\\\n \\midrule\n \\multirow{2}{*}{\\textit{\\textbf{Typa A}}} & \\textit{\\textbf{A1}} & 60 \\% & 20 \\% & 20 \\% \\\\\n & \\textit{\\textbf{B2}} & 50 \\% & 40 \\% & 10 \\% \\\\\n \\multirow{2}{*}{\\textit{\\textbf{Typa B}}} & \\textit{\\textbf{A1}} & 30 \\% & 10 \\% & 60 \\% \\\\\n & \\textit{\\textbf{B2}} & 5 \\% & 90 \\% & 5 \\% \\\\\n \\bottomrule\n \\end{tabular}\n\\end{figure}\n```\n\nResult:\n\n<p align=\"center\"><img src=\"./.images/complex.jpg\" alt=\"simple\" width=480></p>\n\n## Latex packages\n\nAccording the commands you use, some packages may need to be added to the\ndocument for the correct rendering of the table.\n\nTo see the dependencies for a given table you can use de `render_deps` method:\n\n```python\n# following the example from the last section\nprint(table.render_deps())\n```\n\nOutput:\n```\n\\usepackage{multirow}\n\\usepackage{booktabs}\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2022 yupidevs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Python library for rendering latex tables in an easy way",
"version": "0.2.0",
"project_urls": {
"Homepage": "https://github.com/jmorgadov/etabs"
},
"split_keywords": [
"latex",
" table"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "78094c9c787dba235d998906868d36041d5667b918c102d04247849d1135c23f",
"md5": "bf986f1b05b5e45bf210cfef8fc93b31",
"sha256": "b829053922f1f5299b12e5eca096a2650b234720630bf044bc324ee11b571c49"
},
"downloads": -1,
"filename": "etabs-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bf986f1b05b5e45bf210cfef8fc93b31",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9095,
"upload_time": "2024-10-21T09:54:53",
"upload_time_iso_8601": "2024-10-21T09:54:53.624446Z",
"url": "https://files.pythonhosted.org/packages/78/09/4c9c787dba235d998906868d36041d5667b918c102d04247849d1135c23f/etabs-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "05576d98f167d5cbe7f129047411a630f798998d01ea90624c3c31c4d898d9d0",
"md5": "e01627954709299512b2f2c16c6319d8",
"sha256": "259b9e6e63a788c36bcc7281f891ab8cfa4984da2f94fd6200b8664d620c4ca0"
},
"downloads": -1,
"filename": "etabs-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "e01627954709299512b2f2c16c6319d8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 10232,
"upload_time": "2024-10-21T09:54:55",
"upload_time_iso_8601": "2024-10-21T09:54:55.142246Z",
"url": "https://files.pythonhosted.org/packages/05/57/6d98f167d5cbe7f129047411a630f798998d01ea90624c3c31c4d898d9d0/etabs-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-21 09:54:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jmorgadov",
"github_project": "etabs",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "etabs"
}