将三张桌子叠放在一起

将三张桌子叠放在一起

我通常在图形和表格环境中工作时会遇到问题。对于我的论文,我使用它将xtable我的 R 数据输出到 latex 代码中。我有三个矩阵,我想像下图这样堆叠:

在此处输入图片描述

这是我当前的尝试,但错误是“不处于外部 par 模式。\begin

\begin{figure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
        \begin{table}
            \begin{tabular}{rrrrrrrrrrr}
                \hline
                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ 
                \hline
                A & 0.10 & -1.64 & 1.17 & 0.50 & 0.81 & 0.63 & 1.00 & 0.31 & 1.00 & 0.07 \\ 
                C & 0.55 & 0.30 & -1.87 & -1.48 & -2.97 & -2.72 & -1.86 & -2.01 & -3.26 & -1.39 \\ 
                G & -1.72 & -2.75 & -1.35 & -1.70 & -2.65 & -2.54 & -2.93 & -1.59 & 0.11 & 0.88 \\ 
                T & -0.01 & 0.87 & -1.03 & 0.66 & 0.49 & 0.68 & 0.07 & 0.83 & -2.04 & -1.31 \\
                \hline
            \end{tabular}
        \end{table}
        \caption{$y=x$}
        \label{fig:y equals x}
    \end{subfigure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
        \begin{table}
            \begin{tabular}{rrrrrrrrrrr}
                \hline
                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ 
                \hline
                A & 518 &  91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\ 
                C & 809 & 631 &  72 & 107 &  24 &  31 &  73 &  63 &  18 & 117 \\ 
                G &  84 &  30 & 121 &  86 &  33 &  37 &  25 &  96 & 524 & 1130 \\ 
                T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 &  61 & 126 \\ 
                \hline
            \end{tabular}
        \end{table}
        \caption{$y=x$}
        \label{fig:y equals x}
    \end{subfigure}

    \hfill
    \begin{subfigure}[b]{0.3\textwidth}
        \centering
        \begin{table}[ht]

            \begin{tabular}{rrrrrrrrrrr}
                \hline
                & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ 
                \hline
                A & 0.28 & 0.05 & 0.81 & 0.41 & 0.56 & 0.47 & 0.68 & 0.34 & 0.68 & 0.27 \\ 
                C & 0.43 & 0.34 & 0.04 & 0.06 & 0.01 & 0.02 & 0.04 & 0.03 & 0.01 & 0.06 \\ 
                G & 0.04 & 0.02 & 0.06 & 0.05 & 0.02 & 0.02 & 0.01 & 0.05 & 0.28 & 0.60 \\ 
                T & 0.25 & 0.60 & 0.09 & 0.48 & 0.41 & 0.49 & 0.27 & 0.58 & 0.03 & 0.07 \\ 
                \hline
            \end{tabular}
        \end{table}
        \caption{$y=3sinx$}
        \label{fig:three sin x}
    \end{subfigure}
    \hfill

    \caption{Three simple graphs}
    \label{fig:three graphs}
\end{figure}

答案1

这是一个在环境中使用三个subtable环境(由包提供subcaption)的解决方案table。(由于材料似乎都是表格形式,我建议使用tablesubtable环境而不是figuresubfigure环境。)我使用\bigskip说明在环境之间提供更多的垂直分离subtable

下面的代码还使用了booktabs包的线条绘制宏,以使线条的垂直间距比更好\hline,以及十个数字数据列的S列类型(由包提供)。siunitx

在此处输入图片描述

\documentclass{article}
\usepackage{subcaption,siunitx,booktabs}
\usepackage[margin=1in]{geometry} % choose margins to suit your needs
\begin{document}

\begin{table}

\begin{subtable}{1\textwidth}
\sisetup{table-format=-1.2}   % 2 decimals, leave space for minus sign
\centering
   \begin{tabular}{@{} l*{10}{S} @{}}
      \toprule
      & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\ 
      \midrule
      A & 0.10 & -1.64 & 1.17 & 0.50 & 0.81 & 0.63 & 1.00 & 0.31 & 1.00 & 0.07 \\ 
      C & 0.55 & 0.30 & -1.87 & -1.48 & -2.97 & -2.72 & -1.86 & -2.01 & -3.26 & -1.39 \\ 
      G & -1.72 & -2.75 & -1.35 & -1.70 & -2.65 & -2.54 & -2.93 & -1.59 & 0.11 & 0.88 \\ 
      T & -0.01 & 0.87 & -1.03 & 0.66 & 0.49 & 0.68 & 0.07 & 0.83 & -2.04 & -1.31 \\
      \bottomrule
   \end{tabular}
   \caption{First subtable}\label{tab:sub_first}
\end{subtable}

\bigskip
\begin{subtable}{1\textwidth}
\sisetup{table-format=4.0} % integer values only, up to 4 digits
\centering
   \begin{tabular}{@{} l*{10}{S} @{}}
      \toprule
      & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\ 
      \midrule
      A & 518 &  91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\ 
      C & 809 & 631 &  72 & 107 &  24 &  31 &  73 &  63 &  18 & 117 \\ 
      G &  84 &  30 & 121 &  86 &  33 &  37 &  25 &  96 & 524 & 1130 \\ 
      T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 &  61 & 126 \\ 
      \bottomrule
   \end{tabular}
   \caption{Second subtable}\label{tab:sub_second}
\end{subtable}

\bigskip
\begin{subtable}{1\textwidth}
\sisetup{table-format=1.2} % up to two decimal digits, no minus signs
\centering
   \begin{tabular}{@{} l*{10}{S} @{}}
      \toprule
      & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\ 
      \midrule
      A & 0.28 & 0.05 & 0.81 & 0.41 & 0.56 & 0.47 & 0.68 & 0.34 & 0.68 & 0.27 \\ 
      C & 0.43 & 0.34 & 0.04 & 0.06 & 0.01 & 0.02 & 0.04 & 0.03 & 0.01 & 0.06 \\ 
      G & 0.04 & 0.02 & 0.06 & 0.05 & 0.02 & 0.02 & 0.01 & 0.05 & 0.28 & 0.60 \\ 
      T & 0.25 & 0.60 & 0.09 & 0.48 & 0.41 & 0.49 & 0.27 & 0.58 & 0.03 & 0.07 \\ 
      \bottomrule
   \end{tabular}
   \caption{Third subtable}\label{tab:sub_third}
\end{subtable}

\caption{Three simple tables} \label{tab:three_tables}
\end{table}
\end{document}

答案2

以下是使用该floatrow包的两种解决方案。您可以将表格堆叠为单独的表格或子表格。我给出了两种方法的示例。请注意,由于某种原因,表格编号存在差距,我不得不进行弥补:

\documentclass[11pt, a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[textwidth = 14cm]{geometry}
\usepackage{caption, subcaption, booktabs}

\usepackage{floatrow}
\DeclareFloatVCode{somespace}{\vspace{1.667\baselineskip}}
\floatsetup{rowpostcode =somespace, margins = centering}

\begin{document}

\begin{table}[!h]
%
\ttabbox{%
\begin{tabular}{*{11}{r}}
  \toprule
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
  \midrule
  A & 518 & 91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\
  C & 809 & 631 & 72 & 107 & 24 & 31 & 73 & 63 & 18 & 117 \\
  G & 84 & 30 & 121 & 86 & 33 & 37 & 25 & 96 & 524 & 1130 \\
  T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 & 61 & 126 \\
  \bottomrule
\end{tabular}
}{\caption{Table gives an overview about the average positioning errors for each algorithm used in the first test.}
\label{tab:one}}%

\ttabbox{%
\begin{tabular}{*{11}{r}}
  \toprule
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
  \midrule
  A & 518 & 91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\
  C & 809 & 631 & 72 & 107 & 24 & 31 & 73 & 63 & 18 & 117 \\
  G & 84 & 30 & 121 & 86 & 33 & 37 & 25 & 96 & 524 & 1130 \\
  T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 & 61 & 126 \\
  \bottomrule
\end{tabular}
}{\caption{Table gives an overview about the average positioning errors for each algorithm used in the first test.}
\label{tab:two}}%

  \ttabbox{%
    \begin{tabular}{*{11}{r}}
      \toprule
        & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
      \midrule
      A & 518 & 91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\
      C & 809 & 631 & 72 & 107 & 24 & 31 & 73 & 63 & 18 & 117 \\
      G & 84 & 30 & 121 & 86 & 33 & 37 & 25 & 96 & 524 & 1130 \\
      T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 & 61 & 126 \\
      \bottomrule
    \end{tabular}
    }{\caption{Table gives an overview about the average positioning errors for each algorithm used in the first test.}
    \label{tab:three}}%
  %%
  {\caption{Three tables}\label{tab: onetothree}}
\end{table}

\begin{table}[!h]
  \ttabbox[\linewidth]{
    \begin{subfloatrow}
      \ttabbox{%
        \begin{tabular}{*{11}{r}}
          \toprule
            & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
          \midrule
          A & 518 & 91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\
          C & 809 & 631 & 72 & 107 & 24 & 31 & 73 & 63 & 18 & 117 \\
          G & 84 & 30 & 121 & 86 & 33 & 37 & 25 & 96 & 524 & 1130 \\
          T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 & 61 & 126 \\
          \bottomrule
        \end{tabular}
        }{\caption{Table gives an overview about the average positioning errors for each algorithm used in the first test.}
        \label{tab:one}}
    \end{subfloatrow}%
\begin{subfloatrow}
  \ttabbox{%
    \begin{tabular}{*{11}{r}}
      \toprule
        & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
      \midrule
      A & 518 & 91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\
      C & 809 & 631 & 72 & 107 & 24 & 31 & 73 & 63 & 18 & 117 \\
      G & 84 & 30 & 121 & 86 & 33 & 37 & 25 & 96 & 524 & 1130 \\
      T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 & 61 & 126 \\
      \bottomrule
    \end{tabular}
    }{\caption{Table gives an overview about the average positioning errors for each algorithm used in the first test.}
    \label{tab:three}}%
\end{subfloatrow}

\begin{subfloatrow}
  \ttabbox{%
    \begin{tabular}{*{11}{r}}
      \toprule
        & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
      \midrule
      A & 518 & 91 & 1515 & 773 & 1054 & 880 & 1276 & 637 & 1272 & 502 \\
      C & 809 & 631 & 72 & 107 & 24 & 31 & 73 & 63 & 18 & 117 \\
      G & 84 & 30 & 121 & 86 & 33 & 37 & 25 & 96 & 524 & 1130 \\
      T & 464 & 1123 & 167 & 909 & 764 & 927 & 501 & 1079 & 61 & 126 \\
      \bottomrule
    \end{tabular}
  }%
  {\caption{Table gives an overview about the average positioning errors for each algorithm used in the first test.}
    \label{tab:three}}%
    \end{subfloatrow}
  }
  {\caption{Three tables}\label{tab: onetothree}}
\end{table}

\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容