我正在通过将DataFrame
传递到to_latex()
来创建表,该表将生成无边界的表。有什么办法添加吗?
答案 0 :(得分:0)
import re # Use regular expression to search for column declaration section of LaTeX table
tex_content = df.to_latex(index=True, escape=False) #Or whatever options you want/need
print(tex_content)
re_borders = re.compile(r"begin\{tabular\}\{([^\}]+)\}")
borders = re_borders.findall(tex_content)[0]
borders = '|'.join(list(borders))
tex_content = re_borders.sub("begin{tabular}{" + borders + "}", tex_content)
print(tex_content)
# Or save tex_content to a ".tex" file
答案 1 :(得分:-1)
请参阅https://www.overleaf.com/learn/latex/Tables
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
cell1 & cell2 & cell3 \\
cell4 & cell5 & cell6 \\
cell7 & cell8 & cell9 \\
\hline
\end{tabular}
\end{center}