3

I want to rotate a table, When I use sideways table environment table disappears from the document and also disappear from list of tables. I tried a lot with different possible packages as below. I need the whole table environment(label, caption etc) to rotate.

\documentclass[12pt]{report}
   \renewcommand{\baselinestretch}{1.5}
   \usepackage[top=1in, bottom=1in, left=1.25in, right=0.75in]{geometry}
                 \usepackage[utf8]{inputenc}
                 \usepackage{amsmath}
                 \usepackage{csvsimple}
                 \usepackage{amssymb}
                 \usepackage{longtable}
                 \usepackage{booktabs}
                 \usepackage{adjustbox}
                 \usepackage{placeins}
                 \usepackage{float}
                 \usepackage{wrapfig}
                 \usepackage{array}
                 \usepackage{tabularx}
                 \usepackage{tabu}
                 \usepackage{setspace} 
                 \usepackage{multirow} 
                 \usepackage{rotating}
                 \usepackage{multirow}
                 \usepackage{longtable}

                 \usepackage{enumitem}
                 \usepackage{pifont}
                 \usepackage{natbib}
                 \usepackage{booktabs}
                 \usepackage{collcell}
                 \usepackage{datatool}
                 \usepackage{pdflscape}
                 \usepackage{graphics}
\begin{document}

\begin{sidewaystable}[H]
    \centering
    \caption{Set table like this}
    \vspace{2mm}
    \begin{tabular}{cccccccccc}\toprule
        &       & Data set 1 &       &       & Data set 2 &       &       & Data set 3 &  \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
        Estimators & $ n=10 $  & $ n=15 $  & $ n=20 $  & n=10  & $ n=15 $  & $ n=20 $  & $ n=10 $  & $ n=15 $  & $ n=20 $\\ \midrule
        $ \hat{M}_{01} $   & 100.451 & 101.658 & 100.012 & 103.402 & 119.517 & 311.625 & 110.256 & 126.864 & 157.835 \\
        $ \hat{M}_{02} $   & 59.146 & 7407.001 & 1508.683 & 448.119 & 326.131 & 788.717 & 189.374 & 153.392 & 285.499 \\
        $ \hat{M}_{03} $   & 2896.694 & 2828.759 & 1154.403 & 974.536 & 1931.318 & 12350 & 1150.055 & 2778.052 & 1245.779 \\ \bottomrule
    \end{tabular}%
    \label{tex table}%
\end{sidewaystable}%

\end{document}
  • Welcome to TeX SX! I don't think you have to use [H] for sideways table, as it puts the table on a page of its own. – Bernard Jan 30 '17 at 9:23
  • 1
    I added some notes about [H] to my answer – David Carlisle Jan 30 '17 at 9:35
  • @Bernard - Not only does the [H] option not "have to be" used when using sidewaystable environments, it must not be used. David's answer and comments reveals this issue in more detail. – Mico Jan 30 '17 at 9:35
  • Yes its works when i remove [H]. Bundle of thanks to all of you... @DavidCarlisle, Bernard, Mico – Ibrahim M Jan 30 '17 at 10:43
4

You don't show what you did so it is not possible to say what is wrong with that, but if you change \begin{table}[H] to \begin{sidewaystable} and change \end{table} to \end{sidewaystable} then you get

enter image description here


If you use [H] on sidewaystable without using the float package then you get an error

! LaTeX Error: Unknown float option `H'.

However when the float package is loaded H gets allowed in the optional argument but doesn't actually work for sidewaystable which causes the text to be silently dropped, which is not ideal.

One could argue whether this is a failing in the rotating or float package but since I only have write access to rotating I'll say it is an issue with float. I'll ping its maintainer....

  • I tried it with \begin{sidewaystable} and \end{sidewaystable} but it's not working, still disappears the table – Ibrahim M Jan 30 '17 at 9:19
  • 1
    @IbrahimM text should never disappear without warning. First fix your question so that it has an example of the problem not an example of a document that does not use sidewaystable at all, and then show the log file from the example document so we see what warnings are given. – David Carlisle Jan 30 '17 at 9:25
  • 1
    @IbrahimM No you did not try it as above you tried it with [H] which is not a legal option. – David Carlisle Jan 30 '17 at 9:27
  • @Mico well I added some text to relate to the question after the question was edited. I don't think it's enough just to say you shouldn't use H (H should have worked, or latex should give an error). – David Carlisle Jan 30 '17 at 9:36
  • 1
    With sidewaystable the contents is typeset and boxed with lrbox. But the H option causes this to be performed inside a \vbox and, when \end{sidewaystable} is found, first the \vbox is closed, then the box register \rot@float@box is delivered, but it's empty, by now. – egreg Jan 30 '17 at 11:44
3

What happens is roughly the following:

  1. sidewaystable is essentially similar to table, with the difference that instead of executing \@float{table}[<pref>] it does

    \@float{table}[<pref>]\begin{lrbox}{\rot@float@box}
    
  2. when \end{sidewaystable} is found, \end{lrbox} is done, followed by some maintenance jobs and eventually by \end@float.

In the above code, <pref> stands for the explicit positioning preferences or the default ones.

In the case of \begin{sidewaystable}[H], TeX will find

\@float{table}[H]\begin{lrbox}{\rot@float@box}

and now float kicks in. It changes \@float to examine the options; if H is found, it does

\@float@HH{sidewaystable}[H]

which gobbles [H], does some maintenance jobs among which redefining \endsidewaystable to be \float@endH and starts setting a \vbox in the register \@currbox.

At the moment \end{sidewaystable} is scanned, there are two boxes being formed: \rot@float@box and \@currbox. Since \begin{lrbox} does clever tricks with grouping, the box is finished up and after it also \@currbox. But the code of the standard \endsidewaystable that should rotate the box is never executed (and would have no effect anyway, because at the closure of \@currbox, the box saved in \rot@float@box is lost as the register's contents is restored to what it contained before the start of \vbox\@currbox (that is, empty).

Solution: it doesn't make sense to use [H] with sidewaystable.

I'd say even more: a sidewaystable should be avoided as long as possible and it should always be a page float. Setting it as a top float, for instance, would force the reader to do awkward movements for looking at the table; besides, if a sidewaystable fits as a top float, it would most likely fit as a standard (unrotated) table.

  • +1 for "it doesn't make sense to use [H] with sidewaystable". :-) – Mico Jan 30 '17 at 12:59
2

Works for me. I took the opportunity to use siunitx for an alignment of numeric volumns on the decimal dot, and load caption for a correct vertical spacing between caption and table without having to specify \vspace{2mm}, and corrected some errors/inconsistencies. In particular, as pointed by @David Carlisle, the [H] specifier should not be used with sidewaystable.

\documentclass[12pt]{report}
\renewcommand{\baselinestretch}{1.5}
\usepackage[top=1in, bottom=1in, left=1.25in, right=0.75in]{geometry}
             \usepackage[utf8]{inputenc}
             \usepackage{amsmath}
             \usepackage{csvsimple}
             \usepackage{amssymb}
             \usepackage{longtable}
             \usepackage{booktabs}
             \usepackage{adjustbox}
             \usepackage{placeins}
             \usepackage{float}
             \usepackage{wrapfig}
             \usepackage{array}
             \usepackage{tabularx}
            \usepackage{tabu}
             \usepackage{setspace}
             \usepackage{multirow}
             \usepackage{rotating}
             \usepackage{longtable}

             \usepackage{enumitem}
             \usepackage{pifont}
             \usepackage{natbib}
             \usepackage{booktabs}
             \usepackage{collcell}
             \usepackage{datatool}
             \usepackage{pdflscape}
             \usepackage{graphicx}
            \usepackage{siunitx} %
            \usepackage{caption} %

\begin{document}

\begin{sidewaystable}%[H]
    \centering\sisetup{table-format =4.3, table-number-alignment=center}
    \caption{Set table like this}
    \begin{tabular}{c*{9}{S}}\toprule
        & & {Data set 1} & & & {Data set 2} & & & {Data set 3} & \\ %\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
        Estimators & {$n=10 $} & {$ n=15 $} & {$ n=20 $} & {n=10} & {$ n=15 $} & {$ n=20 $} & {$ n=10 $} & {$ n=15 $} & {$ n=20 $}\\ \midrule
        $ \hat{M}_{01} $ & 100.451 & 101.658 & 100.012 & 103.402 & 119.517 & 311.625 & 110.256 & 126.864 & 157.835 \\
        $ \hat{M}_{02} $ & 59.146 & 7407.001 & 1508.683 & 448.119 & 326.131 & 788.717 & 189.374 & 153.392 & 285.499 \\
        $ \hat{M}_{03} $ & 2896.694 & 2828.759 & 1154.403 & 974.536 & 1931.318 & 12350 & 1150.055 & 2778.052 & 1245.779 \\ \bottomrule
    \end{tabular}%
    \label{tex table}%
\end{sidewaystable}%

\end{document} 

enter image description here

  • While certainly nifty in terms of using the S column type for the 9 data columns, your answer doesn't address the OP's main problem, viz., the disappearance of the entire table. You may want to add a sentence (and/or make a cross-reference to David C.'s answer) to note that the [H] location specifier must not be used with sidewaystable environments. – Mico Jan 30 '17 at 10:00
  • 1
    @Mico: Done; I contented myself with commenting the specifier, but you're right: what goes well without saying, goes even better when you say it. – Bernard Jan 30 '17 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.