如何在 Julia 中将 Dataframe 保存为 pdf 文件?

Ana*_*ngh 6 pdflatex julia

我在将数据帧转换为 pdf 文件时遇到困难。我尝试先转换为 Latex,然后转换为 pdf,但问题是我使用 Latexify 包将数据帧转换为 Latex 格式,但 Latexify() 函数的输出不正确,因为当转换为 pdf 时,它会给出扭曲的表格。那么,你能帮我一下吗?这是示例代码

\n
using DataFrames\nusing PrettyTables\nusing LaTeXStrings\nusing Latexify\n# Create a DataFrame\ndf = DataFrame(A = [1, 2, 3], B = [4, 5, 6], C = [7, 8, 9])\n# Convert the DataFrame to a LaTeX table\nlatex_table = latexify(df,latex=false)\n# Print the LaTeX table\nprintln(latex_table)\n# Define the LaTeX document as a string\nlatex_doc = \xe2\x80\x9c\xe2\x80\x9d"\n\\\\documentclass{article}\n\\\\usepackage{booktabs}\n\\\\begin{document}\n$latex_table\n\\\\end{document}\n\xe2\x80\x9c\xe2\x80\x9d"\n# Save the LaTeX document to a file\nwrite(\xe2\x80\x9cmydoc.tex\xe2\x80\x9d, latex_doc)\n# Define the name of the LaTeX file\nlatex_file = \xe2\x80\x9cmydoc.tex\xe2\x80\x9d\n# Run the pdflatex command to generate the PDF file\nrun(`pdflatex $latex_file`)\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试LatexifyPrettyTables打包,使用latexify()函数我得到了一个输出,当保存到 PDF 文件时,该输出给出了扭曲的表格。我与在线 Latex 到 pdf 转换器进行交叉检查,发现latexify()输出不正确。使用PrettyTables包,我试图创建数据框的乳胶输出,但未能成功。

\n

因此,请建议我应该用来将数据帧保存到 PDF 文件的包、函数或标志。

\n

Bog*_*ski 8

这是将数据帧输出到 LaTeX 的方法:

\n
julia> using DataFrames\n\njulia> df = DataFrame(A = [1, 2, 3], B = [4, 5, 6], C = [7, 8, 9])\n3\xc3\x973 DataFrame\n Row \xe2\x94\x82 A      B      C\n     \xe2\x94\x82 Int64  Int64  Int64\n\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n   1 \xe2\x94\x82     1      4      7\n   2 \xe2\x94\x82     2      5      8\n   3 \xe2\x94\x82     3      6      9\n\njulia> show(stdout, MIME("text/latex"), df)\n\\begin{tabular}{r|ccc}\n        & A & B & C\\\\\n        \\hline\n        & Int64 & Int64 & Int64\\\\\n        \\hline\n        1 & 1 & 4 & 7 \\\\\n        2 & 2 & 5 & 8 \\\\\n        3 & 3 & 6 & 9 \\\\\n\\end{tabular}\n
Run Code Online (Sandbox Code Playgroud)\n

这里我用stdout输出来显示结果。但stdout您可以使用任何流来写入表内容。

\n

如果您需要更多解释,请评论。

\n