LaTeX含图片表格边框不均问题排查求助
LaTeX表格边框不均问题排查与解决
我尝试在LaTeX文档中插入三张图片并放在表格内,但表格无法为每个单元格提供均等的边框,效果如下:
原代码:
\makeatletter \newcommand\extralabel[2]{{\edef\@currentlabel{\@currentlabel#2}\label{#1}}} \makeatother \begin{figure} \centering \begin{tabular}{|c|c|c|} \hline \\ \includegraphics[height=4.5cm]{example-image-b} & \includegraphics[height=4.5cm]{example-image-b} & \includegraphics[height=4.5cm]{example-image-b} \\ \hline \textbf{(a)} & \textbf{(b)} & \textbf{(c)} \\ \hline \end{tabular} \caption{ \textbf{(a)} Some text \textbf{(b)} Some text \textbf{(c)} Some text } \label{fig:Name} \extralabel{fig:Name:a}{(a)} \extralabel{fig:Name:b}{(b)} \extralabel{fig:Name:c}{(c)} \end{figure}
问题原因
- 第一行
\hline后多余的\\导致第一个单元格顶部产生额外空白,使得该单元格边框高度明显大于其他单元格。 - 图片所在行与下方标注行的单元格高度不匹配,进一步放大了边框不均的视觉效果。
解决方案
方案1:将图片与标注放在同一单元格(推荐)
把每个图片和对应的标注放在同一个单元格内,确保每个单元格的内容高度一致,边框自然均等。修正后的代码:
\makeatletter \newcommand\extralabel[2]{{\edef\@currentlabel{\@currentlabel#2}\label{#1}}} \makeatother \begin{figure} \centering \begin{tabular}{|c|c|c|} \hline \includegraphics[height=4.5cm]{example-image-b} \\ \textbf{(a)} & \includegraphics[height=4.5cm]{example-image-b} \\ \textbf{(b)} & \includegraphics[height=4.5cm]{example-image-b} \\ \textbf{(c)} \\ \hline \end{tabular} \caption{ \textbf{(a)} Some text \textbf{(b)} Some text \textbf{(c)} Some text } \label{fig:Name} \extralabel{fig:Name:a}{(a)} \extralabel{fig:Name:b}{(b)} \extralabel{fig:Name:c}{(c)} \end{figure}
方案2:修正原表格的换行问题
如果坚持分两行布局,需要去掉多余换行并调整行间距,保证上下单元格高度匹配:
\makeatletter \newcommand\extralabel[2]{{\edef\@currentlabel{\@currentlabel#2}\label{#1}}} \makeatother \begin{figure} \centering % 调整表格行间距,让上下单元格高度更协调 \renewcommand{\arraystretch}{1.2} \begin{tabular}{|c|c|c|} \hline \includegraphics[height=4.5cm]{example-image-b} & \includegraphics[height=4.5cm]{example-image-b} & \includegraphics[height=4.5cm]{example-image-b} \\ \hline \textbf{(a)} & \textbf{(b)} & \textbf{(c)} \\ \hline \end{tabular} \caption{ \textbf{(a)} Some text \textbf{(b)} Some text \textbf{(c)} Some text } \label{fig:Name} \extralabel{fig:Name:a}{(a)} \extralabel{fig:Name:b}{(b)} \extralabel{fig:Name:c}{(c)} \end{figure}
内容的提问来源于stack exchange,提问作者Yustina Ivanova
相关产品推荐
相关产品推荐

