如何使用LaTeX在Jupyter笔记本中水平包含两个图形,准备导出为PDF?

2024-04-18 06:21:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我想包括两个图,如图here

我尝试使用标记语法,但是,当导出为PDF时,这两个图像超出了页面的范围。Pandoc无法将HTML转换为LaTeX,反之亦然,因此在HTML中包含图形也不是一个选项

最后,使用(some) LaTeX environments for Jupyter notebook我能够将LaTeX代码包含到标记单元格中,以便它显示在笔记本本身中。不过,我现在有两个问题。这是我的代码:

\begin{figure}[ht]
\begin{subfigure}{.5\textwidth}
  \centering
  % include first image
  \includegraphics[width=.8\linewidth]{attachments/alpha-games.jpg}  
  \caption{AlphaZero games}
  \label{fig:games}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
  \centering
  % include second image
  \includegraphics[width=.8\linewidth]{attachments/fb-robots.jpg}  
  \caption{Robots}
  \label{fig:robots}
\end{subfigure}
\caption{Uses of Reinforcement learning in real life.}
\label{fig:fig1}
\end{figure}

这是Jupyter笔记本中的输出:

Jupyter Notebook output

只显示一个图像,另一个不显示。此外,地物标题未居中

这是另一个问题,图形标题不在图像下方居中,而是向左对齐。即使在简单图形下(不是子图形)

因此,我需要的是在Jupyter笔记本中以及通过LaTeX将笔记本转换为PDF后正确显示数字。

有什么想法吗?谢谢大家!


Tags: 标记图像图形pdfhtmlfig笔记本jupyter