3

I use the subtables environment from the subfloat package to combine table numbering (i.e., any tables I wrap in the subtables environment get labeled 1a, 1b, and so on). But I just learned on the LaTeX wiki how to use the subfloat environment from the subfig package for figures and it seems that I should use the subfloat environment from the subfig package for tables, too. Is this correct?

The rub is that I frequently use the sidewaystable environment from the rotating package. Can I rotate tables using the subfloat environment from the subfig package? (I can't figure out how from the manual.) This would allow side-by-side sideways tables. Or should I stick with my more naive approach using the subfloat package?

Here is an example of how I combine the subtables and sidewaystable environments.

\documentclass{article}
\usepackage{subfloat}
\usepackage{rotating}

\begin{document}

Check out tables \ref{tab:first} and \ref{tab:second}.

\begin{subtables}
    \begin{sidewaystable}
        \centering
        \begin{tabular}{ccc}
            \hline
            a&b&c\\
            d&e&f\\
            \hline
        \end{tabular}
        \caption{my first table}
        \label{tab:first}
    \end{sidewaystable}

    \begin{sidewaystable}
        \centering
        \begin{tabular}{ccc}
            \hline
            a&b&c\\
            d&e&f\\
            \hline
        \end{tabular}
        \caption{my second table, which is the same as the first}
        \label{tab:second}
    \end{sidewaystable}
\end{subtables}

\end{document}
David Carlisle
  • 757,742
  • 1
    did you mean to have each subfloat on a separate page? -- i would expect to have the subfloat environments inside a single sidewaystable environment. – wasteofspace Jan 21 '12 at 14:44
  • @anon -- Thanks. I didn't know that I could wrap multiple tabulars in one sidewaystable. Is there a good book on LaTeX? I learn most of this stuff in a vacuum, but the other programs I use (R, Stata) have consoles and help commands. Thanks! – Richard Herron Jan 21 '12 at 18:30

2 Answers2

3

It is possible to obtain a sidewaystable look with multiple tables turned sideways without using subfig or even rotating. Here is a minimal example (which uses subfloat for numbering):

enter image description here

\documentclass{article}
\usepackage{subfloat}% http://ctan.org/pkg/subfloat
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\begin{document}

Check out Tables~\ref{tab:first} and~\ref{tab:second}.

\begin{subtables} \begin{table}[ht] \centering \rotatebox{90}{% Rotate table 90 degree CCW \begin{minipage}{0.5\linewidth} \centering \begin{tabular}{ccc} \hline a&b&c\ d&e&f\ \hline \end{tabular} \caption{my first table}\label{tab:first} \end{minipage} } \qquad% <-------------- separation between sideways tables \rotatebox{90}{% Rotate table by 90 degree CCW \begin{minipage}{0.5\linewidth} \centering \begin{tabular}{ccc} \hline a&b&c\ d&e&f\ \hline \end{tabular} \caption{my second table, which is the same as the first}\label{tab:second} \end{minipage} } \end{table} \end{subtables}

\end{document}

Rotation of the tables are obtained via graphicx's \rotatebox{<angle>}{<stuff>}. However, for tables (like tabular with a \caption), you need to box the contents you're rotating. I've done so using a minipage of width 0.5\linewidth. This length is required, but you can also use the varwidth which provides a similarly-named environment as an analogue to minipage, but shrinks (if needed) to the natural width of the box.

The space between "subtables" is given by \qquad, although a \hspace{<len>} would also work (where <len> is any recognized TeX length).

Finally, the table has been set as a float with specification [ht], which is different from sidewaystable's necessary [p] (page of floats) usage. However, you can modify this to suit.

For the moment, this does not incorporate rotating's on-the-fly +/90 degree rotating of floats which is page-dependent (which rotates the tables 90 degrees CCW for odd-numbered pages, and 90 degrees CW for even-numbered pages). However, it would be possible to implement such a feature using some additional packages like chngpage, for example.

Werner
  • 603,163
0

Here is another answer, which uses the \sidewaystable and \subfloat as requested:

\documentclass{article}
%\usepackage{subcaption} %should be used instead of subfig
\usepackage{subfig}
\usepackage{rotating}

\begin{document}

Check out tables \ref{tab:first} and \ref{tab:second}.

\begin{sidewaystable}[!h] \centering \caption{Example of subfloat and tables}\label{tab:main} \subfloat[][my first table\label{tab:first}]{ \begin{tabular}{ccc} \hline a&b&c\ d&e&f\ \hline \end{tabular} }

    \vspace{2em}

    \subfloat[][my second table, which is the same as the first\label{tab:second}]{
    \begin{tabular}{ccc}
        \hline
        a&amp;b&amp;c\\
        d&amp;e&amp;f\\
        \hline
    \end{tabular}
    }
\end{sidewaystable}

\end{document}

Producing the following: referencing

enter image description here

... and tables on a new page (because of sidewaystable)

enter image description here

Note that, as described here, you may want to use subcaption package instead of subfig. (Just replace the package in the code above and the example works the same way)

lcorag
  • 101