16

I have a few long tables that should be rotated 90 degrees. These tables pretty much need to take up their own page. Rotating the table itself is not a problem, but I would also like to have an attribute set in the appropriate page that made pdf viewers view the page in landscape mode.

I have read this question and this question and there is plenty of information for doing what I want using the landscape environment from pdflscape. Except for one problem: the table produced in these ways is not really a float. The landscape environment is not itself a float, so my tables take up a whole page, and the page that precedes them is full of whitespace.

Is there any way to designate the page containing some float as landscape while letting the float continue to float? Can I make a landscape-float environment? I don't mind if such a thing necessarily has to take up a whole page. If I have to, I'll resort to using sidewaystable from the rotating package and post-processing the pdf on pages that need rotating, but it would be nice to not have to do that every time I need to recompile the final draft.

2 Answers 2

11

Since the rotated table will take up a full page anyway (not as complex to position as a partial-page float), you can use afterpage to avoid breaking up the text flow.

\documentclass{article}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{lipsum} % for filler text only

\begin{document}
\pagestyle{myheadings} % to show header behavior
\lipsum
\afterpage{%
  \begin{landscape}
    \begin{table}[p]
      \caption{Rotated table caption.}
      \lipsum[1]
    \end{table}
  \end{landscape}
}
\lipsum
\end{document}
2
  • Does this solution keep the headers at the top of the page when viewed as a portrait page? The solution I ended up with (that I just posted) does that, which was desired. Jan 30, 2014 at 8:01
  • @alex: Yes indeed, it does. I was trying to use global attrs (see your solution) at first also, but I too had scope issues in certain viewers. Jan 30, 2014 at 10:25
9

I ended up using the following construct:

main file had:

\input{tex file with the table}

and the tex file with the table had:

\afterpage{\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}}
\begin{sidewaystable}
...
\end{sidewaystable}
\afterpage{\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}

and it worked perfectly with the original tables that I had in mind when I asked this question.

Here's an interesting thing though. Later in the document a second full page sideways table arose and I tried the exact same approach. I'm on a Mac and use TeXShop. In both the TeXShop pdf viewer and Preview, a few pages that followed the second table (which should have resumed to portrait viewing) stayed in landscape. Then portrait viewing resumed for a few pages. But then the last few pages went back to landscape viewing (and should not have). This was pretty bizarre behavior and I confirmed it happening on someone else's iPad viewing of the pdf (may have been Preview again). But perhaps even stranger was that if we opened the pdf using an Adobe viewer (on a Mac or a PC) or with Sumatra on a PC, only the appropriate pages viewed in landscape mode.

I eventually resolved the issue by pulling the line

    \afterpage{\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}

out of the input tex file and putting it directly in the main file after the \input call. After this, all these pdf viewers behaved with the document as desired. It's strange that different pdf viewers behaved differently. I'm willing to chalk this up to a problem with those pdf viewers and not with tex. But I thought it worth noting here.

1
  • 1
    +1 very nice :) really glad you got this working in our document- it does make a significant different to the readability on-screen
    – cmhughes
    Jan 31, 2014 at 2:57

You must log in to answer this question.

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