26

Is it possible to include "table code" as a sub-figure (instead of an image) using the package subfig? If so, how?

0

2 Answers 2

26

You can include any content (table, text, figure, ...) within a figure or table environment. That is, there is no restriction to only have figures within a figure environment, nor to only have a tabular within a table environment. The same goes for \subfloat from the \subfig package. The respective environments just maintain different counters and they end up in different "List of ..."s - administrative differences of sorts.

Here's a minimal example:

enter image description here

\documentclass{article}
\usepackage{subfig}% http://ctan.org/pkg/subfig
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\newcommand{\mytab}{% Just for this example
  \begin{tabular}{lcr}
    \toprule
    One & Two & Three \\
    \midrule
    $x$ & $y$ & $z$ \\
    1 & 2 & 3 \\
    \bottomrule
  \end{tabular}
}
\begin{document}

\begin{figure}%
  \centering
  \subfloat[][]{\mytab}%
  \qquad
  \subfloat[][]{\mytab}
  \caption{Here are some tables in a \texttt{figure} environment.}%
  \label{fig:table}%
\end{figure}

\begin{table}%
  \centering
  \subfloat[][]{\mytab}%
  \qquad
  \subfloat[][]{\mytab}
  \caption{Here are some tables in a \texttt{table} environment.}%
  \label{tbl:table}%
\end{table}

\end{document}​
3
  • 2
    Is caption label the only difference between figure and table ? I really don't know this. Mar 8, 2012 at 21:35
  • Which % is/are really necessary in your code above? Mar 8, 2012 at 21:36
  • @DamienWalters: As mentioned, the caption label displays differently, the environments maintain different counters and end up in different "List of..."s, but apart from that, they're the same things - an environment that can float. In the above code, perhaps only % following \subfloat seems necessary (not exactly sure). I took the example from the subfig documentation.
    – Werner
    Mar 8, 2012 at 21:44
0

Use package \usepackage{subfig}, and the latex code is

\begin{table}[htb]
\centering
\subfloat[Caption for subtable 1]{%
\begin{tabular}{ |c|c|c| }
\hline
Regressor Model & Train & Test \\
\hline

\end{tabular}}
\quad % Adjust the spacing between subtables if needed
\subfloat[Caption for subtable 2]{%
\begin{tabular}{ |c|c|c| }
\hline
Regressor Model & Train & Test \\
\hline
% Add your table content here
\end{tabular}%
}
\caption{Overall table caption}
\label{tab:mytable}
\end{table}
New contributor
Snehal Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You must log in to answer this question.

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