Nbconvert:输出数据帧或图片后,LaTeX格式损坏

时间:2020-05-01 19:44:49

标签: latex jupyter nbconvert

在我的工作流程中,我使用nbconvert将Jupyter Notebooks转换为LaTeX。这样做时,我确实会遇到这样的问题:每当我输出熊猫数据帧或图片时,我的后续markdown单元在LaTeX中的格式就会错误。我已经建立了一个最小的示例,该示例也显示了也是available on GitHub的数据框的问题。运行下面显示的Jupyter笔记本

enter image description here

生成一个.tex文件,该文件可以编译为以下PDF:

enter image description here

可以看出,第二个markdown单元与字体和其上方数据框的居中有关。对于接下来的所有降价单元,这都是正确的,这使得转换后的笔记本基本上无法使用。

我能够进一步找到问题所在。将单元格4的{​​{1}}输出与生成的LaTeX代码中的数据帧进行比较时:

2+2

您可以看到第二个Out语句周围缺少 \begin{tcolorbox}[breakable, size=fbox, boxrule=.5pt, pad at break*=1mm, opacityfill=0] \prompt{Out}{outcolor}{23}{\boxspacing} \begin{Verbatim}[commandchars=\\\{\}] 4 \end{Verbatim} \end{tcolorbox} \prompt{Out}{outcolor}{24}{} {\begin{tabular}{lrrrr} \toprule {} & A & B & C & D \\ \midrule A & 1 & 2 & 3 & 4 \\ B & 1 & 2 & 3 & 4 \\ C & 1 & 2 & 3 & 4 \\ D & 1 & 2 & 3 & 4 \\ \bottomrule \end{tabular} } 。这就是导致此问题的原因。手动将数据框包装在与{tcolorbox}输出相同的{tcolorbox}中即可解决此问题。如何获得nbconvert始终将4消息包装在Out中?我已经开始阅读customizing nbconvert,但坦率地说,这有点让人不知所措。

0 个答案:

没有答案
相关问题