我想在\figure
环境中添加一个表格,这样图中就有了一个表格以下它。我想这样做,这样我就可以在这张表中加上一个标题来解释这个图和它的结果。
\begin{figure}[!htbp]
\centering
\includegraphics[width=90mm]{fig.pdf}
\vspace{-5em}
% This table does not appear
\begin{table}
\def\arraystretch{1.3}
\resizebox{\columnwidth}{!}
{
\begin{tabular}{ >{\centering\arraybackslash} m{0.4cm} >{\centering\arraybackslash} m{1.4cm} >{\centering\arraybackslash} m{1.4cm} >{\centering\arraybackslash} m{1.4cm} }
\hline
\vspace{0.12in}
\shortstack{\textbf{Links}\\ \color{white} } &
\shortstack{\textbf{Scenario 1} \\ (Tree)} &
\shortstack{\textbf{Scenario 2} \\ (Graph)} &
\shortstack{\textbf{Scenario 3} \\ (Matrix)} \\
\hline
\end{tabular}
}
\end{table}
%%%%%%%%%%% End of table %%%%%%%%%%%%
\caption{Figure and its result from the experiment}
\label{fig}
\end{figure}
答案1
将浮点数嵌套在浮点数中并不是将图像和表格合并为一个浮点数的子浮点数的正确方法这可以简单地完成,如下面的 MWE 所示:
\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tabularx}% added for table design
\usepackage{show frame}% for show page layout, in real use it had to be removed
\usepackage{lipsum}% for dummy text
\begin{document}
\begin{figure}[ht]
\centering
\begin{subfigure}{.7\columnwidth}
\includegraphics[width=\linewidth]{example-image}
\caption{picture}
\end{subfigure}
\bigskip% <-- added
\begin{subfigure}{\columnwidth}<-- changed width
\centering
\renewcommand\tabularxcolumn[1]{m{#1}}% <-- added
\renewcommand\arraystretch{1.3}
\setlength\tabcolsep{2pt}% <-- added
\begin{tabularx}{\linewidth}{*{4}{>{\centering\arraybackslash}X}}% <-- changed
\hline
\textbf{Links} & \textbf{Scenario 1} & \textbf{Scenario 2} & \textbf{Scenario 3} \\
??? & (tree) & (Graph) & (Matrix) \\
\hline
\end{tabularx}
\caption{table}
\end{subfigure}
\caption{Some wonderful words.}
\label{my label}
\end{figure}
\lipsum[1-5]
\end{document}
答案2
\centering\arraybackslash
我不认为这是浮点数在浮点数中的问题,我认为这是和其他东西的问题。如果我用一个普通的表做一个简单的例子,它就可以工作:
\documentclass[preview]{standalone}
\usepackage{amsmath}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[H]
\centering
\begin{subfigure}{.7\textwidth}
\includegraphics[width=90mm]{X}
\caption{picture}
\end{subfigure}
\begin{subfigure}{.7\textwidth}
\begin{table}
\centering
\begin{tabular}{|c|c|c|}
\hline
$A$ & $v_1$ & $\sum_a^b$ \\ \hline
105 & 452 & tree \\ \hline
\end{tabular}
\caption{table}
\end{table}
\end{subfigure}
\caption{some wonderful words.}
\label{thisisalabel}
\end{figure}
\end{document}
结果如下: