|
From: | Richard H Stanton |
Subject: | Re: How to specify column alignment in LaTeX table output? |
Date: | Fri, 10 Jan 2025 09:04:53 -0800 |
On Jan 9, 2025, at 10:13 PM, Pedro Andres Aranda Gutierrez <paaguti@gmail.com> wrote:
Thanks for the suggestion! I was creating the output in a rather similar way, using the pandas to_markdown() function, which calls tabulate to do the work. Using the orgtbl output option, it only prints one horizontal line under the header, so I created a simple wrapper function to add additional horizontal lines at top and bottom (and optionally between the last and penultimate lines, for when there’s a “Total” row): ----- def add_hlines(table, total_row=False): """Add horizontal lines to markdown table.""" table_markdown = table.to_markdown(index=False, tablefmt="orgtbl", floatfmt=",.2f") table_lines = table_markdown.split("\n") hline = table_lines[1] table_lines.insert(0, hline) if total_row: table_lines.insert(-1, hline) table_lines.append(hline) return "\n".join(table_lines) ----- |
[Prev in Thread] | Current Thread | [Next in Thread] |