I'd like to have landscape (tcolorbox) floats, and the naive way of doing them with afterpage and pdflscape does not really work. While I did get the result I wanted for print, I would also like to have the landscape pages rotated in the PDF just like with pdflscape. Since all my landscape figures will be on float pages, I use \iffloatpage, but this is not enough because I have other portrait figures that should not be rotated.
The only solution I can see would be adding a ref for each landscape float page, and then at the beginning of each page, check if the page of the ref is the current page, and if so, rotate the page. But that seems very complicated. Surely, there is a simpler way of knowing whether the float is a landscape float or not.
Another potential solution would be to simply assume that all landscape floats will be immediately after the current page, i.e. store the current page number in a counter, and at the beginning of each new page, rotate the page and decrement the counter, until the counter reaches 0. The problem is that if there are already portrait floats waiting, this might not rotate the right pages.
\documentclass[10pt,a4paper]{scrarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xparse}
\usepackage[most]{tcolorbox}
\usepackage{atbegshi}
\usepackage{fancyhdr}
\begin{document}
\NewDocumentCommand{\setpdfrotation}{m}{
\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate #1}
}
\tcbset{
enhanced,
breakable
}
\tcbset{
landscapefloat/.style={
float=p,
width=\textheight,
tikz={rotate=90,transform shape},
break at=\textwidth
}
}
\AtBeginShipout{%
\AtBeginShipoutAddToBox{%
\iffloatpage{\setpdfrotation{90}}{}%
}%
}
\begin{tcolorbox}[title={Landscape figure}, landscapefloat]%
\textcolor{yellow}{\rule{15cm}{5cm}}\
\textcolor{orange}{\rule{15cm}{5cm}}\
\textcolor{red}{\rule{15cm}{5cm}}\
\textcolor{purple}{\rule{15cm}{5cm}}\
\textcolor{blue}{\rule{15cm}{5cm}}\
\textcolor{green}{\rule{15cm}{5cm}}
\end{tcolorbox}
Some text
\begin{tcolorbox}[title={Portrait figure}, float=p]%
This should not be rotated.
\end{tcolorbox}
\end{document}
watermark textseems to disable overlays, but this can be fixed by replacing it withoverlay app) – xavierm02 Jun 01 '23 at 09:07