景观(tcolorbox)浮动

景观(tcolorbox)浮动

我想要横向(tcolorbox)浮动,以及使用和的简单afterpage方法pdflscape 不起作用。虽然我确实获得了想要的打印结果,但我还想让 PDF 中的横向页面像 一样旋转pdflscape。由于所有横向图形都将位于浮动页面上,因此我使用\iffloatpage,但这还不够,因为我还有其他不应旋转的纵向图形。

我能想到的唯一解决方案是为每个横向浮动页面添加一个引用,然后在每个页面的开头检查引用的页面是否是当前页面,如果是,则旋转页面。但这似乎非常复杂。当然,有一种更简单的方法可以知道浮动是否是横向浮动。

另一个潜在的解决方案是简单地假设所有横向浮动元素都紧跟在当前页面之后,即将当前页码存储在计数器中,并在每个新页面的开头旋转页面并减少计数器,直到计数器达到 0。问题是如果已经有纵向浮动元素在等待,则可能无法旋转正确的页面。

\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}

答案1

使用 pdfmanagement(您用 加载的\DocumentMetadata),您可以在“此页面”上放置旋转。我使用水印密钥将其偷偷放在您的盒子的每个部分上:

\DocumentMetadata{}
\documentclass[10pt,a4paper]{scrarticle}
\usepackage[T1]{fontenc}
\usepackage[most]{tcolorbox}
\usepackage{fancyhdr}

\ExplSyntaxOn
\NewDocumentCommand{\setpdfrotation}{}{\pdfmanagement_add:nnn{ThisPage}{Rotate}{90}}
\ExplSyntaxOff
\begin{document}



\tcbset{
  enhanced,
  breakable
}

\tcbset{
  landscapefloat/.style={
    float=p,
    width=\textheight,
    tikz={rotate=90,transform shape},
    break at=\textwidth,
    watermark text={\setpdfrotation} 
    }
  }




\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}

答案2

使用这个答案由 Ulrike Fischer 撰写,我得到了一些似乎有效的东西:

\documentclass[10pt,a4paper]{scrarticle}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[most]{tcolorbox}
\usepackage{fancyhdr}
\usepackage{pdflscape}
\usepackage{eso-pic,zref-user}
\begin{document}

\newcounter{cntsideways}

\makeatletter

\newcommand\rotatesidewayslabel{\stepcounter{cntsideways}%
 \zlabel{tmp\thecntsideways}\zlabel{rotate\zref@extractdefault{tmp\thecntsideways}{page}{0}}}

\AddToShipoutPictureBG{%
  \ifnum\zref@extractdefault{rotate\number\value{page}}{page}{0}=0%
    \PLS@RemoveRotate%
  \else %
    \PLS@AddRotate{90}%
  \fi%
}
\makeatother

\tcbset{
  enhanced,
  breakable
}

\tcbset{
  landscapefloat/.style={
    float=p,
    width=\textheight,
    tikz={rotate=90,transform shape},
    break at=\textwidth,
    every float={\rotatesidewayslabel}
  }
}

\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}

相关内容