在使用nbconvert从Jupyter导出为pdf时,如何显示宽表的所有DataFrame/表列? [英] How to show all DataFrame/ table columns for wide tables while exporting as pdf from Jupyter using nbconvert?

查看:239
本文介绍了在使用nbconvert从Jupyter导出为pdf时,如何显示宽表的所有DataFrame/表列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题链接到 Jupyter nbconvert LaTex导出主题

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

I am trying to export my Jupyter Notebook as a .pdf using nbconvert through the terminal (on Mac). I already created a .tplx template that will hide the code and show only outputs and markdowns.

# 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表格,该表格继续下一页上的行,但不会将列切片到下一页.相反,它根本不显示它们.这是屏幕截图.

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. Instead, it just doesn't show them at all. Here is the screenshot.

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

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.

推荐答案

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

The article documentclass by default has a textwidth of 345pts, and the table you're attempting to include is just too wide for this. You essentially have two options: make the table smaller, or make the textwidth larger.

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

You could make the textwidth larger by decreasing the size of the margins: for example with \usepackage{geometry}[left=0cm, right=0cm]. Another way you could increase the textwidth would be to use a landscape layout \documentclass[8pt,landscape]{article}.

要减小表的大小,可以查看减小列之间的间隔.例如,您可以尝试\setlength{\tabcolsep}{3pt}(默认分隔为6pt).

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).

如果合适的话,我还将考虑在列名称中缩写国家名称.例如,英国"比英国"占用更少的空间.当然,这将有助于减小表格的宽度.

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". This would certainly help decrease the width of the table.

所有这些选项将在docclass块中指定.即,要设置一个横向页面,在页面之间没有页边距和3pt的间隔.

All of these options would be specified in the docclass block. Ie, to set up a landscape page, with no margins and 3pt between columns you would have.

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

这篇关于在使用nbconvert从Jupyter导出为pdf时,如何显示宽表的所有DataFrame/表列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆