{"id":26593759,"url":"https://github.com/jmorgadov/etabs","last_synced_at":"2025-03-23T15:20:24.543Z","repository":{"id":62159605,"uuid":"558243931","full_name":"jmorgadov/etabs","owner":"jmorgadov","description":"Python library for building and rendering latex tables in an easy way","archived":false,"fork":false,"pushed_at":"2024-10-21T09:54:43.000Z","size":134,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T12:45:26.696Z","etag":null,"topics":["latex","python","table","tabular"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmorgadov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-27T06:57:34.000Z","updated_at":"2025-02-19T10:15:27.000Z","dependencies_parsed_at":"2022-10-27T14:30:27.632Z","dependency_job_id":null,"html_url":"https://github.com/jmorgadov/etabs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmorgadov%2Fetabs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmorgadov%2Fetabs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmorgadov%2Fetabs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmorgadov%2Fetabs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmorgadov","download_url":"https://codeload.github.com/jmorgadov/etabs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244973701,"owners_count":20541025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["latex","python","table","tabular"],"created_at":"2025-03-23T15:20:23.881Z","updated_at":"2025-03-23T15:20:24.524Z","avatar_url":"https://github.com/jmorgadov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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         \u0026 C1 \u0026 C2 \u0026 C3 \\\\\n        \\midrule\n        A \u0026 60 \u0026 20 \u0026 20 \\\\\n        B \u0026 50 \u0026 40 \u0026 10 \\\\\n        C \u0026 30 \u0026 10 \u0026 60 \\\\\n        D \u0026 5 \u0026 90 \u0026 5 \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{figure}\n```\n\nResult:\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./.images/simple.jpg\" alt=\"simple\" width=300\u003e\u003c/p\u003e\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}} \u0026 \\textbf{C1} \u0026 \\textbf{C2} \u0026 \\textbf{C3} \\\\\n        \\midrule\n        \\multirow{2}{*}{\\textit{\\textbf{Typa A}}} \u0026 \\textit{\\textbf{A1}} \u0026 60 \\% \u0026 20 \\% \u0026 20 \\% \\\\\n         \u0026 \\textit{\\textbf{B2}} \u0026 50 \\% \u0026 40 \\% \u0026 10 \\% \\\\\n        \\multirow{2}{*}{\\textit{\\textbf{Typa B}}} \u0026 \\textit{\\textbf{A1}} \u0026 30 \\% \u0026 10 \\% \u0026 60 \\% \\\\\n         \u0026 \\textit{\\textbf{B2}} \u0026 5 \\% \u0026 90 \\% \u0026 5 \\% \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{figure}\n```\n\nResult:\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./.images/complex.jpg\" alt=\"simple\" width=480\u003e\u003c/p\u003e\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmorgadov%2Fetabs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmorgadov%2Fetabs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmorgadov%2Fetabs/lists"}