0

Is it possible to have float-only pages, containing sideways tables or figures produced by the sidewaystable or sidewaysfigure environments of the rotating package, automatically rotated in the PDF output?

This question is related to 3 existing questions:

Rotate single PDF page when viewing

floating sideways table on a rotated page in pdf-viewer

Problems with newpage and pdfpageattr

I've tried the answers given there, based on \pdfpageattr and \afterpage from the afterpage package, with or without \BeforeBeginEnvironment and \AfterEndEnvironment from the etools package, or even modifying directly the definition of sidewaystable say, something like

\makeatletter
\renewenvironment{sidewaystable}
  {\@rotfloat{table}%
   \global\pdfpageattr\expandafter{/Rotate 90}}
  {\afterpage{\global\pdfpageattr\expandafter{/Rotate 0}}%
   \end@rotfloat}
\makeatother

Things always end up like in this screenshot:

Screenshot showing several rotated pages

Namely, not only the page with the actual sideways table is rotated, but also the page where the sidewaystable environment appears in the LaTeX source.

Of course, it's always possible to rotate pages manually in the PDF output, but it would be nice to have sidewaystable etc. rotate the pages automatically. I'm looking for a solution that only rotates the PDF page where the sideways table or figure is floated to, without otherwise altering the formatting in any way (namely, no use of \clearpage, \pagebreak or the landscape environment).

1 Answer 1

1

It depends a bit on the engine how easy it is. With engines using dvi you can use a \special, which is then executed at shipout. luatex has \latelua which can be used too. With pdflatex you have to use a \label/ref system to keep track of the right page. A possible implementation is here https://tex.stackexchange.com/a/472608/2388.

\begin{advertisment}

With the new pdfmanagement of LaTeX which is currently provided as a testphase package you can do this (depending on the engine it will require two compilations):

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}

\documentclass{article}
\usepackage{kantlipsum}
\usepackage{rotating}

\ExplSyntaxOn
\AddToHook{env/sidewaystable/end}{\pdfmanagement_add:nnn{ThisPage}{Rotate}{90}}
\ExplSyntaxOff
\begin{document}
\kant[1]

\begin{table}[t]
\centering\fbox{xxxxxx}\caption{Table}
\end{table}

\kant[1-5]

\begin{sidewaystable}

\begin{tabular}{p{0.8\paperwidth}}
\hline
\kant[1-2]\\
\hline
\end{tabular}

\caption{large sideways table}
\end{sidewaystable}

\kant

\end{document} 

Be aware that it is a testphase package and not yet compatible with everything.

\end{advertisment}

1
  • Many thanks for the speedy response! Both solutions (the original one here and the one at tex.stackexchange.com/a/472608/2388) work perfectly (except with XeTeX for the latter, but that's really minor, I wasn't planning of using XeTeX for this document anyway). I wasn't aware of the future PDF management capabilities of LaTeX; that's very cool indeed, it seems quite natural given the evolution of document processing. I look forward to seeing this included in standard LaTeX. Thanks again! Apr 26, 2021 at 14:58

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.