我通过传递DataFrame
来创建一个表格to_latex()
,它正在生成一个没有边框的表格。有什么办法可以添加吗?
问问题
1607 次
2 回答
1
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
于 2021-04-18T15:56:55.510 回答
-2
参考这个,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}
于 2019-03-18T09:13:00.510 回答