无法在 Latex 文档中并排放置图形和表格

无法在 Latex 文档中并排放置图形和表格

我无法修复这种将图形和表格并排放置的格式。我知道有两种方法可以做到这一点,一种是使用floatrow,另一种是使用minpage。我尝试了这两种方法,但无法执行并得到结果。

这是我的代码,我希望有人能帮我解决我在这里做错的问题。我花了将近 2 个小时,但浪费了。

\begin{figure}
%\begin{floatrow}
    %\begin{minipage}[b]{0.56\linewidth}
    \centering
    \begin{minipage}{0.5\textwidth}
    \centering
    \includegraphics[width=0.45\textwidth]{roc_fi} % you can use other formats too
    \caption{ROC curve tells how much variation in the data is explained by the model, in this is  .        \label{fig:eva}}
    \end{minipage}
%\end{figure}
%\end{minipage}\hfill


\begin{table}
%\begin{minipage}[b]{0.4\linewidth}
    \centering
    \begin{minipage}
    \centering
    \begin{tabular}{|c| p{1,5cm} |c|}
        \hline
        \textbf{Samples} & \textbf{Accuracy} & \textbf{Recall}\\ [0.5ex]
        \hline\hline
        S1 & 0.86 & 0.81 \\
        \hline
        S2 & 0.89 & 0.85 \\
        \hline
        S3 & 0.84 & 0.81 \\
        \hline
        S4 & 0.88 & 0.83 \\
        \hline
        S5 & 0.86 & 0.81 \\
        \hline
        S6 & 0.88 & 0.82\\
        \hline
        S7 & 0.87 & 0.83 \\ 
        \hline
        S8 & 0.82 & 0.78 \\
        \hline
        S9 & 0.87 & 0.83 \\ 
        \hline
        ALL & 0.85 & 0.8 \\ [1ex]
        \hline
    \end{tabular}
    \caption{Validation conducted on several samples of input datasets and the respective measure accuracy and recall are reported here. Both the measures are fairly stable across different samples.\label{tab:table1}}

\end{table}

\end{minipage}

%\end{floatrow}
\end{figure}

答案1

请参阅使用该包的答案floatrow

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx} % remove 'demo' when you compile your document.

\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\begin{document}

\begin{figure}
\begin{floatrow}
\ffigbox{%
  \includegraphics[width=0.45\textwidth]{roc_fi}%
}{%
  \caption{ROC curve tells how much variation in the data is explained by the model, in this is.}
  \label{fig:eva}%
}
\capbtabbox{%
\begin{tabular}{|c| c |c|} \hline 
\textbf{Samples} & \textbf{Accuracy} & \textbf{Recall}\\
\hline \hline 
         S1 & 0.86 & 0.81 \\  \hline
         S2 & 0.89 & 0.85 \\  \hline
         S3 & 0.84 & 0.81 \\   \hline
         S4 & 0.88 & 0.83 \\ \hline
         S5 & 0.86 & 0.81 \\ \hline
         S6 & 0.88 & 0.82  \\ \hline
         S7 & 0.87 & 0.83 \\  \hline
        S8 & 0.82 & 0.78 \\  \hline
        S9 & 0.87 & 0.83 \\ \hline
        ALL & 0.85 & 0.8 \\ \hline
  \end{tabular}
}{%
  \caption{Validation conducted on several samples of input datasets and the respective measure accuracy and recall are reported here. Both the measures are fairly stable across different samples.}%
  \label{tab:table1}
}
\end{floatrow}
\end{figure}

\end{document}

在此处输入图片描述

答案2

看看以下解决方案是否是您想要的:

\documentclass{article}
\usepackage[demo]{graphicx} % in real document remove option "demo"
\usepackage{caption}

\begin{document}
    \begin{figure}
\begin{minipage}{0.56\linewidth}
    \centering
    \includegraphics[width=\linewidth]{roc_fi} % you can use other formats too
    \caption{ROC curve tells how much variation in the data is explained by the model, in this is  .        \label{fig:eva}}
\end{minipage}
\hfill
\begin{minipage}{0.4\linewidth}
    \begin{tabular}{|c| p{1,5cm} |c|}
        \hline
        \textbf{Samples} & \textbf{Accuracy} & \textbf{Recall}\\ [0.5ex]
        \hline\hline
        S1 & 0.86 & 0.81 \\
        \hline
        S2 & 0.89 & 0.85 \\
        \hline
        S3 & 0.84 & 0.81 \\
        \hline
        S4 & 0.88 & 0.83 \\
        \hline
        S5 & 0.86 & 0.81 \\
        \hline
        S6 & 0.88 & 0.82\\
        \hline
        S7 & 0.87 & 0.83 \\
        \hline
        S8 & 0.82 & 0.78 \\
        \hline
        S9 & 0.87 & 0.83 \\
        \hline
        ALL & 0.85 & 0.8 \\ [1ex]
        \hline
    \end{tabular}
    \captionof{table}{Validation conducted on several samples of input datasets and the respective measure accuracy and recall are reported here. Both the measures are fairly stable across different samples.\label{tab:table1}}
\end{minipage}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容