如何解决并排浮动(表格)和 floatrow 包之间的问题?

如何解决并排浮动(表格)和 floatrow 包之间的问题?

我来自这里这个问题被提出但找不到直接的解决方案。我现在有并排表格,我想避免将floatrow包添加到序言中时抛出的错误。有没有办法解决这个问题,如果没有,有没有其他方法可以在不牺牲包的情况下制作并排表格floatrow

MWE 代码:

\documentclass{scrartcl}
%\usepackage{floatrow} % commented out otherwise throws errors (see below)
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\makebox[0pt][c]{\parbox{1\textwidth}{%
    \begin{minipage}[b]{0.5\hsize}\centering
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   3 &   0 &   0 &   0 \\ 
        P &   0 &   5 &   0 &   0 \\ 
        R &   0 &   0 &  19 &   1 \\ 
        Q &   0 &   0 &   0 &  25 \\ 
        \bottomrule 
        \end{tabular}
        \caption{SVMr confusion matrix.}
        \label{tab:cmsvm}
        \vskip 1cm
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   5 &   0 &   0 \\ 
        R &   1 &   0 &  19 &   0 \\ 
        Q &   0 &   0 &   0 &  26 \\ 
        \bottomrule 
        \end{tabular}
        \caption{RDA confusion matrix.}
        \label{tab:cmrda}
        \vskip 1cm
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   3 &   0 &   0 &   0 \\ 
        P &   0 &   4 &   0 &   0 \\ 
        R &   0 &   0 &  19 &   0 \\ 
        Q &   0 &   1 &   0 &  26 \\ 
        \bottomrule 
        \end{tabular}
        \caption{PAM confusion matrix.}
        \label{tab:cmpam}
    \end{minipage}
    \hfil
    \begin{minipage}[b]{0.5\hsize}\centering
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   4 &   0 &   0 \\ 
        R &   1 &   0 &  19 &   0 \\ 
        Q &   0 &   1 &   0 &  26 \\
        \bottomrule 
        \end{tabular}
        \caption{PLS-LDA confusion matrix.}
        \label{tab:cmplslda}
        \vskip 1cm
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   4 &   0 &   0 \\ 
        R &   1 &   0 &  18 &   1 \\ 
        Q &   0 &   1 &   1 &  25 \\
        \bottomrule 
        \end{tabular}
        \caption{LDA confusion matrix.}
        \label{tab:cmlda}
        \vskip 1cm
         \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   3 &   0 &   0 \\ 
        R &   1 &   0 &  12 &   3 \\ 
        Q &   0 &   2 &   7 &  23 \\ 
        \bottomrule 
        \end{tabular}
        \caption{PLS confusion matrix.}
        \label{tab:cmpls}
    \end{minipage}
    \hfil
}}
\end{table}
\end{document}  

输出:
在此处输入图片描述

错误:

Package floatrow Error: Caption(s) lost

答案1

最快的解决方案是使用\RawFloats命令(或rawfloats包选项);有关其他可能的解决方案,请参阅下面的引述:

\documentclass{article}
\usepackage{booktabs}
\usepackage{floatrow}

\begin{document}
\begin{table}
\RawFloats
\centering
\makebox[0pt][c]{\parbox{1\textwidth}{%
    \begin{minipage}[b]{0.5\hsize}\centering
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   3 &   0 &   0 &   0 \\ 
        P &   0 &   5 &   0 &   0 \\ 
        R &   0 &   0 &  19 &   1 \\ 
        Q &   0 &   0 &   0 &  25 \\ 
        \bottomrule 
        \end{tabular}
        \caption{SVMr confusion matrix.}
        \label{tab:cmsvm}
        \vskip 1cm
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   5 &   0 &   0 \\ 
        R &   1 &   0 &  19 &   0 \\ 
        Q &   0 &   0 &   0 &  26 \\ 
        \bottomrule 
        \end{tabular}
        \caption{RDA confusion matrix.}
        \label{tab:cmrda}
        \vskip 1cm
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   3 &   0 &   0 &   0 \\ 
        P &   0 &   4 &   0 &   0 \\ 
        R &   0 &   0 &  19 &   0 \\ 
        Q &   0 &   1 &   0 &  26 \\ 
        \bottomrule 
        \end{tabular}
        \caption{PAM confusion matrix.}
        \label{tab:cmpam}
    \end{minipage}
    \hfil
    \begin{minipage}[b]{0.5\hsize}\centering
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   4 &   0 &   0 \\ 
        R &   1 &   0 &  19 &   0 \\ 
        Q &   0 &   1 &   0 &  26 \\
        \bottomrule 
        \end{tabular}
        \caption{PLS-LDA confusion matrix.}
        \label{tab:cmplslda}
        \vskip 1cm
        \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   4 &   0 &   0 \\ 
        R &   1 &   0 &  18 &   1 \\ 
        Q &   0 &   1 &   1 &  25 \\
        \bottomrule 
        \end{tabular}
        \caption{LDA confusion matrix.}
        \label{tab:cmlda}
        \vskip 1cm
         \begin{tabular}{r|rrrr}
        \toprule
          & \multicolumn{4}{c}{\textbf{Reference}} \\
        \midrule
        \textbf{Predicted}  & H & P & R & Q \\ 
        \midrule
        H &   2 &   0 &   0 &   0 \\ 
        P &   0 &   3 &   0 &   0 \\ 
        R &   1 &   0 &  12 &   3 \\ 
        Q &   0 &   2 &   7 &  23 \\ 
        \bottomrule 
        \end{tabular}
        \caption{PLS confusion matrix.}
        \label{tab:cmpls}
    \end{minipage}
    \hfil
}}
\end{table}
\end{document}

该软件包文档的第 14 页解释了这一现象并提供了解决方案floatrow

下一个例子。如果你按照以下方式放置浮点数:

...
\begin{figure}
\begin{minipage}{0.45\textwidth}
\centering ...
\caption{The figure caption, disappeared, ...}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\captionof{table}{The table caption ...}}
\centering ...
\end{minipage}
\end{figure}

您将收到有关丢失标题的错误消息。您可以这样做:1)将表格内容放在里面,\ttabbox将图形内容放在里面 \ffigbox;然后将两个浮动元素放在floatrow环境中,并且,由于存在混合行(它包含不同类型的浮动元素,并且具有不同的标题位置),将命令放在\killfloatstyle“外部”浮动元素之前\ttabbox,并将\CenterFloatBoxes命令放在环境之前 (有关混合行,请参阅第 2.3.1 节);或 2)使用命令或包选项floatrow恢复标准 LaTeX 行为(第 2.4 节)。\RawFloatsrawfloats

相关内容