简体   繁体   English

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

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

This question is linked to Jupyter nbconvert LaTex Export Theme这个问题链接到Jupyter nbconvert LaTex Export Theme

I am trying to export my Jupyter Notebook as a .pdf using nbconvert through the terminal (on Mac).我正在尝试通过终端(在 Mac 上)使用 nbconvert 将我的 Jupyter Notebook 导出为 .pdf。 I already created a .tplx template that will hide the code and show only outputs and markdowns.我已经创建了一个 .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 *))

What I get with this is a pdf with a table that has the proper style and continues the rows on the next page but it doesn't slice the columns to the next page.我得到的是一个 pdf 表格,该表格具有正确的样式并在下一页上继续行,但它不会将列切到下一页。 Instead, it just doesn't show them at all.相反,它根本不显示它们。 Here is the screenshot.这是屏幕截图。 在此处输入图片说明

I have checked previous posts on SO and I tried to edit the .tplx file using the available documentation, but I couldn't find a solution.我检查了以前关于 SO 的帖子,并尝试使用可用文档编辑 .tplx 文件,但找不到解决方案。

The article documentclass by default has a textwidth of 345pts, and the table you're attempting to include is just too wide for this.默认情况下, article文档类的文本宽度为 345pts,而您尝试包含的表格对于此来说太宽了。 You essentially have two options: make the table smaller, or make the textwidth larger.您基本上有两个选择:使表格变小,或使文本宽度变大。

You could make the textwidth larger by decreasing the size of the margins: for example with \\usepackage{geometry}[left=0cm, right=0cm] .您可以通过减小边距的大小来使 textwidth 更大:例如使用\\usepackage{geometry}[left=0cm, right=0cm] Another way you could increase the textwidth would be to use a landscape layout \\documentclass[8pt,landscape]{article} .另一种增加\\documentclass[8pt,landscape]{article}宽度的方法是使用横向布局\\documentclass[8pt,landscape]{article}

To decrease the size of the table you can look at decreasing the space between columns.要减小表格的大小,您可以考虑减少列之间的空间。 You could try \\setlength{\\tabcolsep}{3pt} for example (the default separation is 6pt).例如,您可以尝试\\setlength{\\tabcolsep}{3pt} (默认分隔为 6pt)。

If appropriate I would also consider abbreviating the names of the countries in the column names.如果合适,我还会考虑在列名称中缩写国家/地区的名称。 Eg "UK" takes up a lot less space than "United Kingdom".例如,“UK”占用的空间比“United Kingdom”少得多。 This would certainly help decrease the width of the table.这肯定有助于减少表格的宽度。

All of these options would be specified in the docclass block.所有这些选项都将在 docclass 块中指定。 Ie, to set up a landscape page, with no margins and 3pt between columns you would have.即,要设置横向页面,您将拥有的列之间没有边距和 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.

相关问题 使用 nbconvert 将 Jupyter 笔记本导出到 PDF 时的模板 - Templates while exporting Jupyter notebook to PDF with nbconvert 在 jupyter 中嵌入图像并使用 nbconvert 将其导出到 PDF 时出错 - Error embedding image in jupyter and exporting it to PDF with nbconvert 如何使用nbconvert+pandoc渲染pdf中的pd.DataFrame表 - How to render pd.DataFrame table in pdf with nbconvert+pandoc 仅显示从Jupyter Notebook用nbconvert创建的pdf中的特定(带标签)输入单元格 - Show only specific (tagged) input cells in pdf created with nbconvert from jupyter notebook 如何使用 nbconvert 从 Jupyter Notebook 到 HTML - How to use nbconvert from Jupyter Notebook to HTML 我需要什么降价模板,以便在使用nbconvert导出时,Jupyter笔记本中的输出单元格看起来与输入单元格不同 - What markdown template do I need such that output cells in Jupyter notebooks look different from input cells when exporting using nbconvert 将jupyter笔记本转换为pdf(彩色) - nbconvert jupyter notebook to pdf (with color) Nbconvert 不显示来自 jupyter notebook 的 styler dataframe - Nbconvert doesn't display styler dataframe from jupyter notebook 从长到宽将Pandas DataFrame重塑,同时添加许多列 - Reshaping pandas DataFrame from long to wide while adding many columns 将 groupedby pandas 数据框(多列但不是所有列)从长转换为宽 - Transforming groupedby pandas dataframe (multiple but not all columns) from long to wide
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM