繁体   English   中英

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

[英]How to show all DataFrame/ table columns for wide tables while exporting as pdf from Jupyter using nbconvert?

这个问题链接到Jupyter nbconvert LaTex Export Theme

我正在尝试通过终端(在 Mac 上)使用 nbconvert 将我的 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 表格,该表格具有正确的样式并在下一页上继续行,但它不会将列切到下一页。 相反,它根本不显示它们。 这是屏幕截图。 在此处输入图片说明

我检查了以前关于 SO 的帖子,并尝试使用可用文档编辑 .tplx 文件,但找不到解决方案。

默认情况下, article文档类的文本宽度为 345pts,而您尝试包含的表格对于此来说太宽了。 您基本上有两个选择:使表格变小,或使文本宽度变大。

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

要减小表格的大小,您可以考虑减少列之间的空间。 例如,您可以尝试\\setlength{\\tabcolsep}{3pt} (默认分隔为 6pt)。

如果合适,我还会考虑在列名称中缩写国家/地区的名称。 例如,“UK”占用的空间比“United Kingdom”少得多。 这肯定有助于减少表格的宽度。

所有这些选项都将在 docclass 块中指定。 即,要设置横向页面,您将拥有的列之间没有边距和 3pt。

((* block docclass *))   
\documentclass[8pt,landscape]{article}
\AtBeginDocument{
   \usepackage{graphicx}
   \resizebox{\textwidth}
   \setlength{\tabcolsep}{3pt}
   \usepackage{geometry}[left=0cm, right=0cm]
   }
((* endblock docclass *))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM