Testing tables generated with the Python tabulate package.
Taken from the Quarto tables documentation, the table below uses the Python tabulate package with the IPython display module’s Markdown() function to print a markdown table.
Markdown()
from IPython.display import Markdown from tabulate import tabulate table = [["Sun",696000,1989100000], ["Earth",6371,5973.6], ["Moon",1737,73.5], ["Mars",3390,641.85]] Markdown(tabulate( table, headers=["Planet","R (km)", "mass (x 10^29 kg)"] ))
You can use other table formats from tabulate in combination with Markdown(), as long as they’re supported by Quarto’s rendering engine. For example, below is the output from tabulate() with used tablefmt="grid".
tabulate()
tablefmt="grid"
table = [["spam",42],["eggs",451],["bacon",0]] headers = ["item", "qty"] print(tabulate(table, headers, tablefmt="grid"))
+--------+-------+ | item | qty | +========+=======+ | spam | 42 | +--------+-------+ | eggs | 451 | +--------+-------+ | bacon | 0 | +--------+-------+
When wrapped in Markdown() instead of print(), this renders as a nice HTML table, since Quarto supports grid tables.
print()
Markdown(tabulate(table, headers, tablefmt="grid"))
0