[英]Templates while exporting Jupyter notebook to PDF with nbconvert
[英]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.