Код: Выделить всё
import pandas as pd
# Create a DataFrame
data = {
'Column 1\nLine 2': [1, 2, 3],
'Column 2\nLine 2': [4, 5, 6]
}
df = pd.DataFrame(data)
# Convert DataFrame to LaTeX table
latex_table = df.to_latex(escape=False).replace('\\n', '\\\\')
display(Latex(df.to_latex(index=False)))
Код: Выделить всё
data = {
'Column 1\nLine 2': [99, 2, 3],
'Column 2\nLine 2': [4, 5, 6]
}
df = pd.DataFrame(data)
# Convert DataFrame to a tabulate table in LaTeX format
table_latex = tabulate(df, headers='keys', tablefmt='latex')
# Display the LaTeX table
display(Latex(table_latex))
Код: Выделить всё
---
title: "wow"
format:
pdf:
documentclass: article
keep-tex: false
include-in-header:
text: |
\usepackage{makecell}
--
```{python}
data = {
'\makecell{Column 1 \\ Line 2}': [88, 2, 3],
'\makecell{Column 1 \n Line 2}': [4, 5, 6]
}
df = pd.DataFrame(data)
# Convert DataFrame to a tabulate table in LaTeX format
table_latex = tabulate(df, headers='keys', tablefmt='latex')
# Display the LaTeX table
display(Latex(table_latex))
Я ищу любое решение, которое позволит включать в заголовки столбцов разрывы строк. Кварто версия 1.5.53
Подробнее здесь: https://stackoverflow.com/questions/787 ... ting-table