Jupyter nbconvert LaTex 导出主题

Roo*_*Roo 4 css python latex jupyter-notebook nbconvert

我正在使用 Jupyter Notebook nbconvert(另存为菜单)通过 Latex 导出为 pdf。然而,pdf 文件的状态并不好。例如,一些宽表显示得很好。我希望有一个用于将表格大小调整为页面宽度的框。是否有任何样式、模板可以用来生成漂亮的报告以及如何要求 nbconverter 使用该样式?

这是乳胶输出:

在此输入图像描述

我想要这样的东西:

在此输入图像描述

but*_*gon 5

看起来 Pandas._repr_latex_()在 0.23 版本中获得了一个方法。您需要进行设置pd.options.display.latex.repr=True才能激活它。

没有乳胶代表:
不含乳胶制品
与乳胶代表:
与乳胶代表

查看选项以使格式接近您想要的格式。为了准确匹配您所需的输出,您需要使用自定义乳胶模板。


编辑以提供有关模板的更多信息:

从这里开始了解有关模板的一般信息。您可以在与笔记本相同的路径中创建一个文件,并在从命令行.tplx运行时将其指定为模板: 。或者,您可以通过修改目录中的文件来指定通过菜单导出为 Latex 时要使用的默认模板。如果此文件尚不存在,您可以通过从命令行运行命令来生成它。我的模板也位于该目录中,因此我将以下内容添加到我的: nbconvert!jupyter nbconvert --to python 'example.ipynb' --stdout --template=my_custom_template.tplxjupyter_notebook_config.py~.jupyterjupyter notebook --generate-config~/.jupyterjupyter_notebook_config.py

# Insert this at the top of the file to allow you to reference
# a template in the ~.jupyter directory
import os.path
import sys
sys.path.insert(0, os.path.expanduser("~") + '/.jupyter')
# Insert this at the bottom of the file:
c.LatexExporter.template_file = 'my_template' # no .tplx extension here
c.LatexExporter.template_path = ['.', os.path.expanduser("~") + '/.jupyter'] # nbconvert will look in ~/.jupyter
Run Code Online (Sandbox Code Playgroud)

要了解一些有关模板如何工作的信息,请首先查看null.tplx。该线((*- for cell in nb.cells -*))循环遍历笔记本中的所有单元格。接下来的语句if检查每个单元格的类型并调用适当的块。

其他模板扩展了null.tplx. 每个模板定义(或重新定义)一些块。层次结构是null->display_priority->document_contents->base->style_*->article.

您的自定义模板可能应该扩展article.tplx一些 Latex 命令并将其添加到标题中,以按照您想要的方式设置表格。请查看此博客文章,了解设置自定义模板的示例。