我有 8 张图片,其中我想要横向放置 2 张图片,纵向放置 4 张图片。我尝试使用以下代码执行此操作:
\begin{figure}[htb]
\centering
\begin{tabular}{@{}cccc@{}}
\includegraphics[scale=0.4]{../random_forest/TP-Pred/program/error1.jpg}
\includegraphics[scale=0.4]{../random_forest/AFP-AFP-like/program/error1.jpg}
\includegraphics[scale=0.4]{../random_forest/TP-Pred/program/error1.jpg}
\includegraphics[scale=0.4]{../random_forest/AFP-AFP-like/program/error1.jpg}
\multicolumn{4}{c}{\includegraphics[width=.23\textwidth]{example-image-a}}
\end{tabular}
\caption{A plot of the random forest error split culmulatively over the 4 sets of features}
\end{figure}
但是所有 4 幅图像都显示在同一水平线上。我该如何让它们看起来像这样:
image 1 image 2
image 3 image 4
image 5 image 6
image 7 image 8
提前致谢。
答案1
我猜这 8 张 jpeg 大小都一样,对吧?如果是那样的话,就不需要将它们嵌入到环境中tabular
。您可以改为执行以下操作:
\begin{figure}[htb]
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image1.jpg}%
\hspace*{\fill}% induce some horizontal separation between images 1 and 2
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image2.jpg}
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image3.jpg}%
\hspace*{\fill}% induce some horizontal separation between images 3 and 4
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image4.jpg}
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image5.jpg}%
\hspace*{\fill}% induce some horizontal separation between images 5 and 6
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image6.jpg}
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image7.jpg}%
\hspace*{\fill}% induce some horizontal separation between images 7 and 8
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image8.jpg}
\caption{A plot of the random forest error split culmulatively over the 4 sets of features}
\end{figure}
请注意,空白行会自动强制以下图像显示在新“行”上。如果您想要的垂直间隔大于最小值,则可以插入诸如\smallskip
、\medskip
或 之类的指令\bigskip
(同时仍留出空白行以强制换行)。
附录:如果您确实想要/需要将图像嵌入表格结构中,我建议您使用环境tabular*
并将其宽度设置为,\textwidth
以便为图像分配尽可能多的宽度。看起来有点奇怪的构造@{\extracolsep{\fill}}
将两列最大限度地分开。
\begin{figure}[htb]
\begin{tabular*}{\textwidth}{@{} c @{\extracolsep{\fill}} c @{}}
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image1.jpg}&
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image2.jpg}\\
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image3.jpg}&
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image4.jpg}\\
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image5.jpg}&
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image6.jpg}\\
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image7.jpg}&
\includegraphics[width=0.45\textwidth]{../random_forest/TP-Pred/image8.jpg}\\
\end{tabular*}
\caption{A plot of the random forest error split culmulatively over the 4 sets of features}
\end{figure}