如何将图像置于已定义大小的表格的中心?

如何将图像置于已定义大小的表格的中心?

我有一个问题,我的表格包含两个并排的图像,下一行是图像的标题。问题是图像不是并排显示的,而是上下显示的。我的代码:

\begin{table}[!ht]\label{tab:subsecfeeling}
\begin{tabular}{|p{7cm}|p{7cm}|}
\hline
\centering
\includegraphics[width=0.7\linewidth]{Screenshots/Routing/closed_area_ex1.png}
\label{fig:closed_area_ex1}
& 
\begin{center}
\includegraphics[width=0.7\linewidth]{Screenshots/Routing/closed_area_ex3.png}
%\label{fig:closed_area_ex3}
\end{center}
\\ 
\hline
The shown route in this figure is the shortest path from current position to the destination. In this route there exists no closed area. & The shown route in this figure is avoiding the closed door. Therefore the shortest path is to use the way through the next office. \\
\hline 
\end{tabular} 
\end{table}

图片显示图片并不相邻。我希望它们相邻,而不是上下。此外,下一行的文本必须换行。

我也尝试将第二张图片居中,但结果几乎与现在的结果相同。如何将两张图片放在相邻的两列中? 在此处输入图片描述

答案1

快速修复方法是使用center环境。似乎使用了center环境和centering命令。

在此处输入图片描述

代码:

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{table}[!ht]\label{tab:subsecfeeling}
\begin{tabular}{|p{7cm}|p{7cm}|}
\hline
\begin{center}
\includegraphics[width=0.7\linewidth]{Screenshots/Routing/closed_area_ex1.png}
\end{center}
\label{fig:closed_area_ex1}
& 
\begin{center}
\includegraphics[width=0.7\linewidth]{Screenshots/Routing/closed_area_ex3.png}
\end{center}
%\label{fig:closed_area_ex3}
\\ 
\hline
The shown route in this figure is the shortest path from current position to the destination. In this route there exists no closed area. & The shown route in this figure is avoiding the closed door. Therefore the shortest path is to use the way through the next office. \\
\hline 
\end{tabular} 
\end{table}
\end{document}

如果centering首选命令,则需要在右括号前放置一个 \par(或一个空行)。\centering在其前后不留垂直空间。

在此处输入图片描述

代码

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{table}[!ht]\label{tab:subsecfeeling}
\begin{tabular}{|p{7cm}|p{7cm}|}
\hline
{\vspace{0.2cm}\centering
\includegraphics[width=0.7\linewidth]{Screenshots/Routing/closed_area_ex1.png}
\par}
\label{fig:closed_area_ex1}
& 
{\vspace{0.2cm}\centering
\includegraphics[width=0.7\linewidth]{Screenshots/Routing/closed_area_ex3.png}

}
\label{fig:closed_area_ex3}
\\ \hline
The shown route in this figure is the shortest path from current position to the destination. In this route there exists no closed area. & The shown route in this figure is avoiding the closed door. Therefore the shortest path is to use the way through the next office. \\
\hline 
\end{tabular} 
\end{table}
\end{document}

相关内容