[Tex/LaTex] Chapter title and rotated table (with subtables) on the same page

rotatingsubfloatstables

My problem is quite similar to the one described in Problems with landscape mode and Title on the same page. The hvfloats solution suggested there does not work for me, however, because I use multiple subtables. But let me start from the beginning:

In the appendix of my thesis I want to add a wide table that needs to be set in landscape mode. Normally I'd just use the sidewaystable environment, but that leaves the first page of the appendix completely empty except for the chapter heading

\documentclass[a4paper] {scrbook}

\usepackage{rotating}
\usepackage{subcaption}

\begin{document}

\appendix \cleardoublepage
\chapter{Some Data Tables}

\begin{sidewaystable}
  \hspace*{\fill}
  \begin{subtable}{.3\textwidth}
    \rule{\linewidth}{12cm}
  \end{subtable}
  %
  \hspace*{\fill}
  %
  \begin{subtable}{.3\textwidth}
    \rule{\linewidth}{12cm}
  \end{subtable}
  \hspace*{\fill}

  \caption{Table with interesting data}
\end{sidewaystable}

\end{document}

The purpose of the three \hspace*{\fill} is just to center the resulting tables properly on the page.


Realising that sidewaystable refers to \textheight I also tried to temporarily adjust that

\def \textheightTmp \textheight
\def \textheight 0.8\textheightTmp
\begin{sidewaystable}
  [...]
\end{sidewaystable}
\def \textheight \textheightTmp

but this lead to the following error

Appendix A.

! Package caption Error: \setcaptionsubtype outside float.

See the caption package documentation for explanation. Type H
for immediate help.

l.15 \begin{subtable}{.3\textwidth}


As I mentioned at the beginning, hvfloats does not work either because of the subtables

\documentclass[a4paper] {scrbook}

\usepackage{hvfloat}
\usepackage{subcaption}

\begin{document}

\appendix \cleardoublepage
\chapter{Some Data Tables}

\hvFloat[capPos=b,rotAngle=90,nonFloat]{table}{%
  \hspace*{\fill}
  \begin{subtable}{.3\textwidth}
    \rule{\linewidth}{12cm}
  \end{subtable}
  %
  \hspace*{\fill}
  %
  \begin{subtable}{.3\textwidth}
    \rule{\linewidth}{12cm}
  \end{subtable}
  \hspace*{\fill}
}{Table with interesting data}{}

\end{document}

This results in the error:

Appendix A.

! Package caption Error: \setcaptionsubtype outside float.

See the caption package documentation for explanation.
Type H for immediate help.

l.23 }{Table with interesting data}{}


What I want is a rotated table (with subtables) and caption that is placed on the same page as the chapter heading. Space isn't an issue, the table would fit on the page.

Is there any way to do this?

Best Answer

You are facing two problems here:

  1. The hvfloat package does not set \@captype (like an ordinary floating environment does) so the subcaption package has no idea if its commands are used inside a figure, a table, or not within a floating environment at all. This must be fixed by Herbert, however you could use \captionsetup{type=table} as workaround.
  2. The standard document classes set \abovecaptionskip to a value of 10pt, \belowcaptionskip to 0pt. \abovecaptionskip will be used above the caption, and \belowcaptionskip below of it. However, this gives you a obvious problem when a \caption is typeset above a figure or table content since you will get a distance of \belowcaptionskip (=0pt) between caption and content, i.e. no distance of all. There are two different (and incompatible) ways to resolve this situation:

    • \abovecaptionskip will be used between caption and content, \belowcaptionskip will be used between caption and edge of the floating environment. (This has the advantage that you could use the default values of \abovecaptionskip and \belowcaptionskip as set by the document class, and the result will not change at all when using \caption below its contents, as designed by Leslie Lamport.)

    • If the caption is below its content, only \abovecaptionskip is used. If the caption is above its content, only \belowcaptionskip is used. (The skips need to be adjusted for making this work, but you are able to setup different skips for above-captions and below-captions here.)

As you see both methods have its pros and cons, but are unfortunately incompatible. However, KOMA-Script and the (sub)caption package are using the first method while hvfloat seems to use the latter. (I'm not sure about this since I didn't have found the time to look into Herbers sources, but at least hvfloat changes the values of the caption skips and therefore just loading the package will affect the skips of the non-hvfloat-floating environments (and the longtable environment and...) as well.)

To compensate this one needs to write macros to save and restore the skips.

So in total we have:

\documentclass[a4paper] {scrbook}

% Save the values of \abovecaptionskip and \belowcaptionskip into \restorecaptionskips
\edef\restorecaptionskips{%
  \noexpand\setlength\noexpand\abovecaptionskip{\the\abovecaptionskip}%
  \noexpand\setlength\noexpand\belowcaptionskip{\the\belowcaptionskip}}
%\show\restorecaptionskips
\usepackage{hvfloat}
% Save the changed values of \abovecaptionskip and \belowcaptionskip into \restorehvcaptionskips
\edef\restorehvcaptionskips{%
  \noexpand\setlength\noexpand\abovecaptionskip{\the\abovecaptionskip}%
  \noexpand\setlength\noexpand\belowcaptionskip{\the\belowcaptionskip}}
% Restore the values of \abovecaptionskip and \belowcaptionskip
\restorecaptionskips

\usepackage{subcaption}

\begin{document}

\appendix \cleardoublepage
\chapter{Some Data Tables}

\restorehvcaptionskips % only needed if "capPos=t"
\hvFloat[capPos=b,rotAngle=90,nonFloat]{table}{%
\restorecaptionskips
\captionsetup{type=table}% set \@captype
  \hspace*{\fill}
  \begin{subtable}{.3\textwidth}
    \rule{\linewidth}{12cm}
  \end{subtable}
  %
  \hspace*{\fill}
  %
  \begin{subtable}{.3\textwidth}
    \rule{\linewidth}{12cm}
  \end{subtable}
  \hspace*{\fill}
}{Table with interesting data}{}
\restorecaptionskips

\end{document}

P.S.: See also http://sourceforge.net/p/latex-caption/tickets/4/

Related Question