我使用“subfloat”在同一个图中可视化图像和表格,如下所示:
\begin{figure}
\centering
\subfloat[Summary statistics\label{subfig-1:tab}]{%
\begin{tabular}{|l|r|}\hline
\textbf{Min.} & 0 \\ \hline
\textbf{1st Qu.} & 0 \\ \hline
\textbf{Median} & 0 \\ \hline
\textbf{Mean} & 88.37 \\ \hline
\textbf{3rd Qu.} & 0 \\ \hline
\textbf{Max.} & 4356 \\ \hline
\textbf{Std} & 404.3 \\ \hline
\end{tabular}
}
\hfill
\subfloat[Histogram\label{subfig-2:histogram}]{%
\includegraphics[width=0.60\textwidth]{capital_loss_histogram.pdf}
}
\caption{Summary statistics and histogram of the attribute capital-loss}
\label{fig:attribute_capital-loss}
\end{figure}
问题是图像没有与表格显示在同一级别,如下图所示:
我怎样才能解决这个问题?
答案1
问题出现的原因在于\includegraphics
将图像的底部沿文本的基线设置,而默认情况下,tabular
环境将表格的中心沿基线放置。这将使表格悬挂得比图形低。可以使用可选参数更改表格的默认对齐方式[b]
,该参数指示LaTeX
将表格的底部沿基线放置,这与图形的对齐方式相同。结果如下:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
\subfloat[Summary statistics\label{subfig-1:tab}]{%
\begin{tabular}[b]{|l|r|}\hline
\textbf{Min.} & 0 \\ \hline
\textbf{1st Qu.} & 0 \\ \hline
\textbf{Median} & 0 \\ \hline
\textbf{Mean} & 88.37 \\ \hline
\textbf{3rd Qu.} & 0 \\ \hline
\textbf{Max.} & 4356 \\ \hline
\textbf{Std} & 404.3 \\ \hline
\end{tabular}
}
\hfill
\subfloat[Histogram\label{subfig-2:histogram}]{%
\includegraphics[width=0.60\textwidth]{capital_loss_histogram.pdf}
}
\caption{Summary statistics and histogram of the attribute capital-loss}
\label{fig:attribute_capital-loss}
\end{figure}
\end{document}