11

I generally have problems working within the figure and table environments. For my thesis I am using xtable to output my R data into latex code. I have three matrices that I would like to stack like the following picture:

enter image description here

Here is my current attempt but the error is `Not in outer par mode. \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}
5
  • 1
    Why subfigure? Couldn't you use an outer table and stack them together?
    – user31729
    Commented Mar 7, 2015 at 18:25
  • I guess I could. Would I be able to reference them separately? ie, figure 1a, 1b, and 1c?
    – masfenix
    Commented Mar 7, 2015 at 18:26
  • @Mico: I don't want to unroll a roll-back. Could you update the post? That is, fix my mistake?
    – Werner
    Commented Mar 7, 2015 at 20:45
  • @Werner - Done. :-)
    – Mico
    Commented Mar 7, 2015 at 21:19
  • 1
    FYI, the table environment just floats its contents, the same as figure. There's no need to wrap every tabular inside a table. The \begin{table} may even be causing your error. Commented Mar 8, 2015 at 5:38

2 Answers 2

12

Here's a solution that uses three subtable environments (provided by the subcaption package) inside a table environment. (Since the material appears to be all tabular, I suggest using table and subtable environments instead of figure and subfigure environments.) I use \bigskip instructions to provide a bit more vertical separation between the subtable environments.

The code below also uses the line-drawing macros of the booktabs package for lines that have better vertical spacing than \hline, as well as the S column type (provided by the siunitx package) for the ten numeric data columns.

enter image description here

\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}
6
  • Thanks mico, could you explainwhat @{} l*{10}{S} @{} does?
    – masfenix
    Commented Mar 7, 2015 at 19:41
  • Also, I get the following picture. anyway to fix this? imgur.com/LL7n30A
    – masfenix
    Commented Mar 7, 2015 at 19:45
  • @masfenix - The opening and closing @{} particles instruct LaTeX not to insert whitespace at the edges of the table; the l particle tells LaTeX to left-align the material in the first column, and *{10}{S} tells LaTeX to set up 10 columns of type S.
    – Mico
    Commented Mar 7, 2015 at 19:45
  • @masfenix - please post the code for the "real" second and third tables. It's necessary to change the \sisetup instruction for those two tables, since their numeric entries aren't integers containing up to four digits. (That's what the \sisetup{table-format=4.0} instruction in my answer is all about.)
    – Mico
    Commented Mar 7, 2015 at 19:49
  • I've added my real tables
    – masfenix
    Commented Mar 7, 2015 at 20:02
7

Here are two solutions, using the floatrow package. You can stack tables either as individual tables or as subtables. I give an example of both ways. Note that for some reason there's a gap in tables numbering, that I had to compensate:

\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}

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .