在使用nbconvert从Jupyter导出为pdf时,如何显示宽表的所有DataFrame /表列?

问题描述 投票:0回答:1

此问题与Jupyter nbconvert LaTex Export Theme链接

[我正在尝试通过nbconvert通过终端(在Mac上)将Jupyter Notebook以.pdf格式导出。我已经创建了一个.tplx模板,该模板将隐藏代码并仅显示输出和减价。

# this is my jupyter notebook heading
pd.set_option('display.notebook_repr_html', True)
pd.set_option('display.expand_frame_repr', True)
pd.set_option("display.latex.repr", True)
pd.set_option("display.latex.longtable", True)
pd.set_option("display.latex.escape", True)
# this is the .tplx template for hiding the input and (preferably) setting the table width
# to fit the page width (including margins)
((*- extends 'article.tplx' -*))

((* block input_group *))
    ((*- if cell.metadata.get('nbconvert', {}).get('show_code', False) -*))
        ((( super() )))
    ((*- endif -*))
((* endblock input_group *))

((* block docclass *))   
\documentclass[8pt]{article}
\AtBeginDocument{
   \usepackage{graphicx}
   \resizebox{\textwidth}
   }
((* endblock docclass *))

我得到的是一个pdf表,该表具有适当的样式,并在下一页上继续行,但不会将列切片到下一页。相反,它根本不显示它们。这是屏幕截图。enter image description here

我检查了SO的先前文章,并尝试使用可用的文档来编辑.tplx文件,但找不到解决方案。

python pandas jupyter-notebook latex nbconvert
1个回答
0
投票

article文档类在默认情况下具有345pts的文本宽度,而您尝试包含的表太宽了。本质上,您有两个选择:使表变小,或使textwidth变大。

您可以通过减小边距的大小来增大文本宽度:例如,使用\usepackage{geometry}[left=0cm, right=0cm]。您可以增加文本宽度的另一种方法是使用横向布局\documentclass[8pt,landscape]{article}

要减小表的大小,您可以看一下减小列之间的间距。您可以尝试使用\setlength{\tabcolsep}{3pt}(默认分隔为6pt)。

[如果适当,我还将考虑在列名称中缩写国家名称。例如,“英国”比“英国”占用更少的空间。这无疑将有助于减小表格的宽度。

所有这些选项都将在docclass块中指定。即,要设置一个横向页面,在页面之间没有空白和3pt的空白。

((* block docclass *))   
\documentclass[8pt,landscape]{article}
\AtBeginDocument{
   \usepackage{graphicx}
   \resizebox{\textwidth}
   \setlength{\tabcolsep}{3pt}
   \usepackage{geometry}[left=0cm, right=0cm]
   }
((* endblock docclass *))
© www.soinside.com 2019 - 2024. All rights reserved.