打算在LaTeX中并排插入两张大小相同的图片,步骤如下:
1. 引入宏包
\usepackage{graphicx}
\usepackage{subcaption}
2. 并排插入子图
\begin{figure}[hbt!]
\centering
\begin{subfigure}[b]{0.5\linewidth}
\centering
\includegraphics[width=\linewidth]{Figures/multi_theme_tsne_title_SBert_Norm.pdf}
\caption{Aspect: Post texts}
\label{fig:TSNE_title}
\end{subfigure}%
\begin{subfigure}[b]{0.5\linewidth}
\centering
\includegraphics[width=\linewidth]{Figures/multi_theme_tsne_comment_SBert_Norm.pdf}
\caption{Aspect: Comments}
\label{fig:TSNE_comment}
\end{subfigure}%
\caption{t-SNE visualization results for different categories. (a) Posts texts; (b) Comments}
\label{fig:TSNE}
\end{figure}
但运行上述代码,结果如下:
无法实现两张子图并排显示的效果。反复检查代码还是没有发现任何问题,后来改成下方代码:
\begin{figure}[hbt!]
\centering
\begin{subfigure}[b]{0.5\linewidth}
\centering
\includegraphics[width=\linewidth]{Figures/multi_theme_tsne_title_SBert_Norm.pdf}
\caption{Aspect: Post texts}
\label{fig:TSNE_title}
\end{subfigure}%
\begin{subfigure}[b]{0.5\linewidth}
\centering
\includegraphics[width=\linewidth]{Figures/multi_theme_tsne_comment_SBert_Norm.pdf}
\caption{Aspect: Comments}
\label{fig:TSNE_comment}
\end{subfigure}%
\caption{t-SNE visualization results for different categories. (a) Posts texts; (b) Comments}
\label{fig:TSNE}
\end{figure}
成功并排!
两段代码唯一的差别就在于{subfigure}
之间有无空行!